0
は、私はテキスト形式で質問をするためのより良い方法を見つけることができませんでした、以下の簡単なシナリオを通過してください:GroovyのSQL +ゴーム
2つのドメインオブジェクトおよびトランザクションサービス:
A {
int id
String prop1
B b
static constraints = {b nullable:true}
}
B {
int id
String prop1
// not worring about belongsTo here
}
SomeService {
def transactional = true
def sessionFactory
def aTransactionalMethod() {
Sql sql = new Sql(sessionFactory.currentSession.connection())
sql# create A some how with sql query leaving property b as null.
A a = A.findById(...)
//a.b must be null here, never mind
sql# create B object somehow with sql query.
// should a.b be available now? I'm getting null here.. session.currentSession.refresh(a) resolves the issue but why is that?
}
}
これがこれを達成する唯一の方法だと思われます。しかし、すべてのSQLをHQLで簡単に書くことはできません。すべての読み込みをSQLに変換する方がよいでしょう。 Gormはストアドプロシージャだけを書く必要があるので、ここで私には役に立ちません。 –
GORMを利用したい場合は、ストアドプロシージャや任意のSQLのHibernateマッピングを調整することができます:http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querysql.html# sp_query –