Mantis - Resin
Viewing Issue Advanced Details
2423 minor always 02-11-08 13:53 03-12-08 12:09
ferg  
ferg  
normal  
closed 3.1.5  
fixed  
none    
none 3.1.6  
0002423: amber eager fetch
(rep by Daniel Spangler)

I preface this with the fact that I'm using a snapshot build
resin-3.1.s080205 because of this bug
(http://bugs.caucho.com/view.php?id=2282). [^]

Even though I have my OneToMany relationship tagged as EAGER, it appears to
behave as if it's in LAZY mode. Here are snippets from my classes.

public class DatabaseQuestionImpl implements Serializable, Question {

...
   @OneToMany(mappedBy="parentQuestion", fetch=FetchType.EAGER, cascade =
CascadeType.ALL)
   private List<DatabaseOptionImpl> optionsFromDatabase;

...
}

public class DatabaseOptionImpl implements Serializable, Option {

...
   @ManyToOne()
   @JoinColumn(name="parent_question_id")
   private DatabaseQuestionImpl parentQuestion;
...
}

Here are logs entries from a case where I do a find(Class, Id) on the
question class, update some fields on it, and then iterate through the
options. You can see that there is a select statement for the question,
then an update statement and then another select statement for the options.
My understanding of EAGER loading is that the find operation should have
retrieved the entire graph. Is this a bug, or a misunderstanding on my
part?

[18:53:49.515] FINE
com.amirsys.pathwork.entity.dynamicquestion.DatabaseQuestionImpl amber
expire com.amirsys.pathwork.entity.dynamicquestion.DatabaseQuestionImpl[1]
[18:53:49.515] FINEST com.caucho.amber.manager.AmberConnection amber
com.amirsys.pathwork.entity.dynamicquestion.DatabaseQuestionImpl[1]
addInternalEntity
[18:53:49.515] FINE com.caucho.sql.spy.SpyConnection.XA
jdbc/postgres.0:setAutoCommit(false)
[18:53:49.515] FINE com.caucho.sql.spy.SpyConnection
jdbc/postgres.0.18:prepareStatement(select o.multipleAnswersPermitted,
o.questionText, o.rootQuestion from question o where
o.id=?,type=1003,concurrency=1007)
[18:53:49.515] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.18:setLong(1,1)
[18:53:49.515] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.18:executeQuery(select o.multipleAnswersPermitted,
o.questionText, o.rootQuestion from question o where o.id=?)
[18:53:49.515] FINER
com.amirsys.pathwork.entity.dynamicquestion.DatabaseQuestionImpl amber
loaded-0 com.amirsys.pathwork.entity.dynamicquestion.DatabaseQuestionImpl
[18:53:49.515] FINER com.caucho.amber.entity.RowInvalidateCompletion
RowInvalidateCompletion table: question key: 1
[18:53:49.515] FINE com.caucho.sql.spy.SpyConnection
jdbc/postgres.0:isClosed() -> false
[18:53:49.515] FINE com.caucho.sql.spy.SpyConnection
jdbc/postgres.0.19:prepareStatement(update question set
multipleAnswersPermitted=?, questionText=?, rootQuestion=? where
id=?,type=1003,concurrency=1007)
[18:53:49.515] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.19:setBoolean(1,true)
[18:53:49.515] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.19:setString(2,What clinical )
[18:53:49.515] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.19:setBoolean(3,true)
[18:53:49.515] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.19:setLong(4,1)
[18:53:49.687] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.19:executeUpdate(update question set
multipleAnswersPermitted=?, questionText=?, rootQuestion=? where id=?) -> 1
[18:53:49.687] FINE
com.amirsys.pathwork.entity.dynamicquestion.DatabaseQuestionImpl amber
update com.amirsys.pathwork.entity.dynamicquestion.DatabaseQuestionImpl -
PK: 1
[18:53:49.687] FINE com.caucho.sql.spy.SpyConnection
jdbc/postgres.0:isClosed() -> false
[18:53:49.687] FINE com.caucho.sql.spy.SpyConnection
jdbc/postgres.0.20:prepareStatement(select c.id, c.followUpQuestionId,
c.freeForm, c.optionType, c.parent_question_id, c.valueAsString from
question o, option c where (c.parent_question_id = o.id) and (o.id =
?),type=1003,concurrency=1007)
[18:53:49.687] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.20:clearParameters()
[18:53:49.687] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.20:setLong(1,1)
[18:53:49.687] FINE com.caucho.sql.spy.SpyPreparedStatement
jdbc/postgres.0.20:executeQuery(select c.id, c.followUpQuestionId,
c.freeForm, c.optionType, c.parent_question_id, c.valueAsString from
question o, option c where (c.parent_question_id = o.id) and (o.id = ?))


Notes
(0002748)
sonstone   
02-11-08 14:04   
Thanks for adding this Scott. A few additional notes...

In the code snippet above I have the ManyToOne annotation for Option->Question with no fetch type associated with it. I noticed in your documentation that the default for Resin is EAGER. My end goal is to have LAZY on that relationship, but I have tried it with both EAGER and LAZY and get the same results as mentioned above.
(0002843)
ferg   
03-12-08 12:09   
jpa/0j05

Amber documentation is at http://caucho.com/resin/doc/amber.xtp [^]

It looks like the eager annotation was being ignored entirely.