-->
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: bidirectional relationship and Lazy Load Exception
PostPosted: Wed Jul 01, 2009 3:28 pm 
Newbie

Joined: Fri Jun 02, 2006 2:49 pm
Posts: 13
I am having a problem with bidirectional relationships, in this pseudo example
I have ObjectA ->ObjectB
ObjectA is many-to-one to ObjectB

I use a JPQL statement to retrieve all the objects using LEFT JOIN FETCH. The problem comes in when I walk down to ObjectB I can not get back to ObjectA. When calling ObjectB.getObjectAs().get(0) I get the famous

Code:
"org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role"


My analysts of the problem is hibernate trying to load all relationships for ObjectB->ObjectA . If that's the case how can I get it to stop doing so, and just use the relationship it already has, If not what is actually causing the exception.

Here is my code if I failed to describe the problem correctly.
Code:
The Query I use

Select screensetDefinition FROM ScreensetDefinition screensetDefinition LEFT JOIN FETCH screensetDefinition.screen screen WHERE screensetDefinition.id = :id


Code:
Object A

@ManyToOne(fetch=FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})   
@JoinColumn(name="Screen_ID", nullable=false)
    public Screen getScreen()
    {
        return this.screen;
    }
   
    public void setScreen(Screen screen)
    {
        this.screen = screen;
    }


Code:
Object B

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "screen")
   public Set<ScreensetDefinition> getScreensetDefinitions()
   {
      return this.screensetDefinitions;
   }

   public void setScreensetDefinitions(Set<ScreensetDefinition> screensetDefinitions)
   {
      this.screensetDefinitions = screensetDefinitions;
   }


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.