java - Hibernate @OneToMany EAGER doesn't work -
java - Hibernate @OneToMany EAGER doesn't work -
i have 2 entities, topics , posts respectively. here's many posts 1 topics.
so had set topics onetomany:
class topics implements serializable { ... @onetomany(fetch = fetchtype.eager, mappedby = "topic") @orderby("date desc") private list<posts> postslist; public list<posts> getpostslist() { homecoming this.postslist; } } in posts entity not specific settings topic field, typical integer.
so problem can't fetch postslist eager fetch type, remain lazy anyway:
topics thetopic = (topics) session.load(topics.class, topic); list<posts> postsoftopic = thetopic.getpostslist(); ... list contains 1 object now, it's total of nulls.
any ideas how fix?
the session.load method typically returns proxy whereas session.get method guaranteed homecoming initialized entity , eagerly fetch collection if marked such. there alternative of using eager fetch hql queries eager load associated collection.
java hibernate relationship
Comments
Post a Comment