java - Hibernate eagerly loads lazy reference -
i have 3 entities a, b , c.
@entity public class { @id private long id; @onetoone(fetch = fetchtype.eager) @joincolumn(name = "id", insertable = false, updatable = false) public b b; } @entity public class b { @id private long id; @onetoone(fetch = fetchtype.lazy) @joincolumn(name = "id", insertable = false, updatable = false) public c c; } @entity public class c { @id private long id; @onetoone(fetch = fetchtype.lazy) @joincolumn(name = "id", insertable = false, updatable = false) public b b; }
so there eagerly loaded reference of b in , between b , c lazily loaded bidirectional relation.
my problem: when fetching instance of db, instance of c fetched hibernate.
i discovered in heap dump due memory leak , tested programmatically:
@test public void eagerandlazyloading() { a = dao.geta(1l); assert.assertnotnull(a); persistenceunitutil puu = emf.getpersistenceunitutil(); assert.asserttrue(puu.isloaded(a)); assert.asserttrue(puu.isloaded(a, "b")); assert.assertfalse(puu.isloaded(a.b, "c")); }
that last assert fails.
luckily there no problem getting rid of bidirectional relation, know source of problem. intended behaviour of hibernate eagerly load references of entity, eagerly loaded?
it seems there problem onetoone lazy loading. there post in hibernate forums explaining why , giving advices( https://forum.hibernate.org/viewtopic.php?f=1&t=1001116 ). suggest try search before ask. think asked here , got answer: try one: making onetoone-relation lazy
Comments
Post a Comment