-->
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: Cascade.PERSIST on merge
PostPosted: Thu May 30, 2013 4:53 am 
Newbie

Joined: Thu May 30, 2013 4:40 am
Posts: 1
Hello,

I read some documentation about cascading, but I don't figure out my problem.

I have two entity :

The entity A have a list of entity B :
Code:
@OneToMany(mappedBy="a",fetch=FetchType.LAZY)
@Cascade({CascadeType.PERSIST})
private List<B> listB;


And the entity B have a relation with the entity A
Code:
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="a", nullable=false)
private A a;


I want to persist, no merge, the entity B when I merge or persit the entity A. So I use the annotation CascadeType.PERSIST on the list of entity B.

But when I do a merge on entity A, I have this error "object references an unsaved transient instance - save the transient instance before merging".

If I use annotation CascadeType.PERSIST and CascadeType.MERGE, this is work fine but I don't want to merge the entity B if they exist, I just want to create them...

Could someone can explain me why this doesn't work ?

Thank you for your time


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.