HI all!!
I've two entities in 1-N relationship.
Class A 1 - N Class B
I'd like to override the standard loader thanks to @Loader annotation (there is so few related documentation :( )
-- Class A --
Code:
@NamedNativeQuery(name = "activeB", query = "select b.* from A a inner join B b on b.a_id = a.id where b.a_id = ? and b.status_id = 1", resultSetMapping = "activeB")
@SqlResultSetMapping(name = "activeB", entities = { @EntityResult(entityClass = B.class) })
...
@OneToMany(mappedBy = "a", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@Sort(type = SortType.NATURAL)
@Loader(namedQuery = "activeB")
public Set<B> getBs() {...}
-- Class B --
Code:
@ManyToOne(optional = true)
public getA() {...}
When i call the method objectA.getBs(); follows the exception:
Code:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: test.loader.A.bs, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
....
What am i wrong???