Hibernate strange createAlias bahaviour
I'm getting a very strange behaviour from Hibernate.
If I execute the following query, everything works as expected:
Criteria crit = session.createCriteria( Message.class )
.add( Restrictions.lt( "sequenceReceived", Long.valueOf( 10 ) ) )
.createAlias( "this.commands", "cmd", CriteriaSpecification.LEFT_JOIN);
"works as expected" means that I obtain a resultSet of Message, where Message.commands were eagerly fetched.
However, the following query does NOT work the same way:
Criteria crit = session.createCriteria( Message.class )
.add( Restrictions.lt( "sequenceReceived", Long.valueOf( 10 ) ) )
.createAlias( "this.commands", "cmd", CriteriaSpecification.LEFT_JOIN, Restrictions.eq( "cmd.priority", 1 ) ));
The only change I've added is an extra restriction for the OUTER LEFT JOIN ON clause. Now the generated SQL became
SELECT [...] FROM messages this_ LEFT OUTER JOIN commands cmd1_ ON this_.unique_key=cmd1_.message_key AND cmd1_.priori开发者_如何学Goty = 1 WHERE this_.sequence_received
The problem is that now, the result set still contains Message, but message.commands is fetched lazily.
Why is this happening, and is there a way to force this loading to be happening eagerly?
Note: I have trie createEntity which yielded an identical behaviour.
精彩评论