-->
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.  [ 3 posts ] 
Author Message
 Post subject: LazyInitializationException on unidirectional many-to-one
PostPosted: Wed May 02, 2007 6:01 pm 
Newbie

Joined: Wed Nov 08, 2006 8:50 am
Posts: 13
Which annotation should I use for this to work?

I am trying:

Code:
    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name = "IdNivel", nullable = false)
    @LazyToOne(value=LazyToOneOption.NO_PROXY)
    public NivelBolsaDTO getNivel() {
   return this.nivel;
    }


But it does not work. Once I close my session, and try to access this property I get an LazyInitializationException.

The object that has the nivel property has a constructor thas accepts the nivel as a parameter. I am creating two new objects with a NivelBolsaDTO loaded from the database but already disconnected from the session and I am trying to add both objects to a collection. The method add fails when on my overrided equals I try to get the value of the nivel property in order to compare it to the other object. Shouldn't this object be created as a regular object, and not a proxy? When I debug I can clearly see that when I create the object, the nivel property is a proxy.

Any explanations?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 6:14 pm 
Newbie

Joined: Wed Nov 08, 2006 8:50 am
Posts: 13
I've figured out what's happenning, but didn't find a way to correct it.

When I load the nivel from the database (sess.load) this load returns a proxy for the object, which in turn I am setting on my detached object. Is there a way for the load not to return a proxy?

Thanks


Top
 Profile  
 
 Post subject: Must be getting crazy
PostPosted: Wed May 02, 2007 9:22 pm 
Newbie

Joined: Wed Nov 08, 2006 8:50 am
Posts: 13
Talking to myself...

So, the answer was... READ THE DOC!!!!

Instead of using session.load() I should be using session.get(), that do not returns a proxy.

I'm feeling a complete moron...


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

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.