-->
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: Cascade-saving won't ignore already persistent beans
PostPosted: Tue Jan 18, 2005 11:28 am 
Newbie

Joined: Mon Nov 29, 2004 10:05 am
Posts: 5
Hello,

I am using Hibernate 2.1.6 and MySQL 4.0.20 to persists beans, and i have trouble getting something done with saveOrUpdate(Object) and cascading.

I have two classes and tables, Institution and Link, such as an Institution can be referenced by multiple Links.

My Institution bean and mappings file have no reference to the Link bean/table. On the other hand, the Link bean has an "institution" property that takes an instance of the Institution class. In the mappings of the Link bean/table, i have defined a many-to-one relation based on that property, with cascade="all".

I am attempting to persist an instance of the Link bean, with an instance of the Institution bean set in its "institution" property. When calling saveOrUpdate(Object) on my Link bean, i expect it to cascade the saving to the Institution property. When neither the Link nor the Institution exist in the database, this works fine - both the Link and the Institution are persisted.

However it can happen that the Institution that is related to my Link already exists in the Institution table (i mean, with the same primary key). I such a case, i would like Hibernate to save the Link and ignore the Institution when cascading, since an Institution with the same primary key already exists. Instead, while the Link is saved, the attempt to cascade the saving to the Institution generates a "duplicate entry" error on the primary key of that Institution.

Is there anything i can do to have Hibernate ignore the already existing Institution?

Thanks in advance for your help,
sf.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 12:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Check your unsaved-value mappigns


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 2:01 pm 
Newbie

Joined: Mon Nov 29, 2004 10:05 am
Posts: 5
In the meantime i think i might have discovered the problem. The mappings for my Institution bean define an assigned identifier, but apparently the reference documentation mentions that objects with such an identifier cannot be persisted using saveOrUpdate(): explicit calls to save() or update() must be performed as applicable... I will look into that.


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.