-->
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: saveOrUpdateCopy & lazy initialization exception
PostPosted: Tue Mar 16, 2004 12:46 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
hi,

when i try to use saveOrUpdateCopy, i've been getting a lazy initialization exception. the object that i'm trying to create has been added to a parent's collection which was loaded in another session. how can i correct this error, do i have to manually associate the parent object to the session with this method?

thanks, cam

Code:
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no Session
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:213)
   at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:69)
   at net.sf.hibernate.collection.Set.iterator(Set.java:131)
   at net.sf.hibernate.type.PersistentCollectionType.copy(PersistentCollectionType.java:248)
   at net.sf.hibernate.type.TypeFactory.copy(TypeFactory.java:284)
   at net.sf.hibernate.impl.SessionImpl.doCopy(SessionImpl.java:3826)
   at net.sf.hibernate.impl.SessionImpl.copy(SessionImpl.java:3784)
   at net.sf.hibernate.engine.Cascades$5.cascade(Cascades.java:132)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:843)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:817)
   at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:740)
   at net.sf.hibernate.impl.SessionImpl.doCopy(SessionImpl.java:3808)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdateCopy(SessionImpl.java:3780)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 4:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ummm ... this should probably not happen. You might want to submit a simplified test case to JIRA. Not sure why you would observe this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 5:21 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
well, i've been having some trouble from a system design point of view and this seemed like a solution until i fully understood what it actually did. what i was really looking for was a saveOrUpdateClone method, or such like. mabye i should explain what i'm trying to accomplish.

i have a wizard which populates an object with primitive values and parent objects. i then attempt to save the object, but if an error occurs i want to try to save the same object again after modifying any offending values or whatever. the problem is that once the object gets passed into the session for the save, it gets assigned an identifier so if i try to save the object again i'll get a error. i had considered just reseting the identifier, but have no way of differentiating between unsaved objects with an identifier, or persisted objects.

so, the reason i was looking at the saveOrUpdateCopy was so that i could attmpt to save a clone of the object so that if it failed i could just re-edit the original and then pass in another clone. like i said, i found out that this isn't what this method does anyway, but i still want to pursue this (prospective) solution.

this has taken a wide step away from hibernate, but what can you recommend i do? i don't really want to have to recreate and repopulate a new object on each attempt. i know this senario probably wont crop up often with lots of validation etc, but i'd like to have the design for it instead of making the user re-enter all the data in the wizard again.

thanks cam

ps. will submit the test i was using to jira


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.