0

以下の簡単なシナリオを実行してください。テキスト形式で質問するためのより良い方法を見つけることができませんでした。

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?
 }
}
4

1 に答える 1

0

HibernateはSQLを解析できないため、データベースに何を書き込んだかを「認識」しません。Hibernateはすべてのセッションオブジェクトをリロードするわけではありません-それは間違いなく大きなオーバーヘッドになります。

クエリをHQLに書き直すと、オブジェクトはすぐにセッションで使用できるようになります。

于 2011-02-21T10:44:39.093 に答える