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.
|