Hibernate version: 2.1.6
Name and version of the database you are using:Oracle 10g
A-->B is one-to-one, constrained=false relation. The code
Code:
s.createQuery("from A a left join fetch a.b").list();
works perfect for me (makes only one select always), but in the same configuration, the following code
Code:
s.createCriteria(A.class).setFetchMode("b", FetchMode.EAGER).list();
results in redundant select for b when there is no B corresponds to A. DEBUG says,
Hibernate: select a.ID, a.NAME, b.ID, b.NAME from A a left outer join B b on a.ID=b.ID
DEBUG - object not resolved in any cache [B#0]
DEBUG - Materializing entity: [B#0]
DEBUG - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG - select b.ID, b.NAME from B b where b.ID = ?
Hibernate : select b.ID, b.NAME from B b where b.ID = ? <--- NO NEED
DEBUG - preparing statement
DEBUG - binding '0' to parameter: 1
DEBUG - processing result set
DEBUG - done processing result set (0 rows)
Is there any suggestion?
Sorry for my poor English.
Thanks you in advance.