hibernate - hql - LazyCollectionOption.FALSE on query -
i have field declaration on role class:
@onetomany(mappedby = "role") private set<user> users;
and query this:
"select r role r left join fetch r.users u"
the users elements size return 1 (incorrect result) should more one. when annotated users field @lazycollection(lazycollectionoption.false)
, , removed fetch
on query, returns collect result.
any idea why cant't work using fetch
on query? not want resort on @lazycollection(lazycollectionoption.false)
expensive call everytime.
update: initial workaround on dao iterate on return list , call getusers on each (using workaround, able retrieve correct count results well).
public list<role> getroles(){ query query = session.createquery("select r role r left join fetch r.users u"); list<role> results = query.list(); (role item: results){ log.info("size {}", item.getusers().size()); } }
will post more code snippet tomorrow overriden equals , hashcode, i'm using 1 generated intellij idea, choosing unique fields include.
make sure implement equals/hashcode methods entities.
the left join fetch should same thing lazy=false. additional select still users collection initialized.
Comments
Post a Comment