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.

  1. make sure implement equals/hashcode methods entities.

  2. the left join fetch should same thing lazy=false. additional select still users collection initialized.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -