[jboss-user] [EJB 3.0] - EJB3 Lazy Load problem

zilbi do-not-reply at jboss.com
Wed Mar 12 13:16:55 EDT 2008


Hi,

i am new to this, so i apologize if this question is stupid...

have 2 entities with 1 to many relations:
@Entity
  | @Table(name = "contents")
  | public class Content implements Serializable
  | {
  |     private Long id;
  |     private Integer version;
  | 	... some more simple fields
  | 
  |     private Collection lastTaggingCollection;
  | 
  |     @ManyToOne
  |     @JoinColumn(name = "last_tagging_collection", nullable = true)
  |     public Collection getLastTaggingCollection()
  |     {
  | 	return lastTaggingCollection;
  |     }
  | 
  |      public void setLastTaggingCollection(Collection lastTaggingCollection)
  |      {
  | 	this.lastTaggingCollection = lastTaggingCollection;
  |      }
  | 
  | 	... more methods
  | }
  | 
  | @Entity
  | @Table(name = "cm_collections")
  | public class Collection implements Serializable
  | {
  |     private Long id;
  |     private Integer version;
  | 	... some more simple fields
  | 
  |     private List<Content> contents;
  | 	
  | 	@OneToMany(fetch = FetchType.LAZY, mappedBy = "lastTaggingCollection")
  | 	@JoinColumn(name = "last_tagging_collection")
  | 	public List<Content> getContents()
  | 	{
  | 		return contents;
  | 	}
  | 
  | 	public void setContents(List<Content> contents)
  | 	{
  | 		this.contents = contents;
  | 	}
  | 
  | 	... more methods
  | }

now, when i am inside a stateless session bean method with a transaction type = required i try the following:
Collection collection = dao.findById( 1L );
  | log.debug("fetchContacts() - caller: " + collection.getContents().size());
(the dao is injected using @EJB)

i get:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jinni.content.mgmt.model.Collection.contents, no session or session was closed


but when i change the fetch type to eager all works...
???

any clue why?
what am i missing?

thanks

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4136044#4136044

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4136044



More information about the jboss-user mailing list