-->
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: Transient collections null after merging detached entity
PostPosted: Thu Sep 06, 2007 6:30 am 
Newbie

Joined: Thu Aug 16, 2007 4:34 am
Posts: 3
Hi everyone,
I am facing a problem that I was not able to solve on my own, thus I ask for your help. I have an entity class which is almost a POJO, containing several properties which should be considered by the persistence provider but I also have another property in the entity class which is a collection and which is annotated as transient.

As soon as I try to merge such a detached entity, the collection - which was non-empty before the merge - becomes empty right after the merge. This is a behaviour that I do not understand and which causes unwanted side effects, because I need to store the entity before processing any further, because I need its ID in order to save the entities that are stored in the collection.

Just in case that you suggest to let the JPA do the dirty work - this is not possible here because some of the entities need transformation prior to persisting.

Could anyone explain this behaviour?

Thank a lot,
Florian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 8:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
merge creates a copy of the persistent data and return a copy, persist makes the object managed.
You might want to check saveOrUpdate (from the Hibernate Session).

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Transient collections null after merging detached entity
PostPosted: Fri Sep 14, 2007 8:04 am 
Newbie

Joined: Fri Oct 22, 2004 4:08 am
Posts: 2
Location: Sweden
I'm having the same problem and I use @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)

In short. Parent class has a collection of Child class.

I invoke EntityManager.merge with a newly created Parent object with associated Child object that are already persistent.

During the execution of EntityManager.merge Hibernate invokes the Parent.setChildren method with an empty Collection


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.