-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @Loader @NativeNamedQuery and lazy initialization issues
PostPosted: Fri May 14, 2010 12:44 pm 
Newbie

Joined: Fri May 14, 2010 12:29 pm
Posts: 1
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???


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.