Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [TENEO] Unable to get "merge" in hibernate list cascade using teneo properties(Not getting "merge" in hibernate list cascade when I use teneo.mapping.cascade_policy_on_non_containment)
[TENEO] Unable to get "merge" in hibernate list cascade using teneo properties [message #1235316] Fri, 24 January 2014 03:38 Go to next message
Minu martin is currently offline Minu martinFriend
Messages: 7
Registered: May 2013
Junior Member
I am using bidirectional relations between classes.
I have a generic application and the entities are generated dynamically run time.
I am trying to create an object of class A along with object of B(which needs to be created along with A) by saving A.
Before performing create I need to do a hibernate merge operation.
This is to avoid exception in case any instance of the request already exists in session as it is a generic application.
But in this case while merging A object which contains B, I am getting a hibernate Exception ObjectNotFoundException for instance B.
I realized that in the hbm file,the list cascade option does not have "merge", it only has "save-update,lock".
Please let me know what settings I need to do to add "merge" also in the cascade of the list.
I am using the teneo property - teneo.mapping.cascade_policy_on_non_containment = persist,merge,refresh

Please find the hbm file generated by teneo below:
<hibernate-mapping auto-import="false">
       <class entity-name="A" abstract="false" lazy="true" table="`a`" proxy="org.eclipse.emf.ecore.impl.DynamicEObjectImpl">
              <meta attribute="eclassName" inherit="false">A</meta>
              <meta attribute="epackage" inherit="false">com.znoo</meta>
              <cache usage="read-write"/>
              <id name="id" type="java.lang.String">
                     <column not-null="true" unique="false" name="`id`"/>
              </id>
              <list name="b" lazy="true" cascade="save-update,lock">
                     <cache usage="read-write"/>
                     <key update="true">
                           <column name="`b_a_id`" unique="false"/>
                     </key>
                     <list-index column="`a_b_idx`"/>
                     <one-to-many entity-name="B"/>
              </list>
       </class>
       <class entity-name="B" abstract="false" lazy="true" table="`b`" proxy="org.eclipse.emf.ecore.impl.DynamicEObjectImpl">
              <meta attribute="eclassName" inherit="false">B</meta>
              <meta attribute="epackage" inherit="false">com.znoo</meta>
              <cache usage="read-write"/>
              <id name="id" type="java.lang.String">
                     <column not-null="true" unique="false" name="`id`"/>
              </id>
              <many-to-one name="a" entity-name="A" lazy="proxy" cascade="merge,persist,save-update,lock,refresh" foreign-key="b_a" insert="false" update="false" not-null="false">
                     <column not-null="false" unique="false" name="`b_a_id`"/>
              </many-to-one>
       </class>
</hibernate-mapping>

[Updated on: Fri, 24 January 2014 03:40]

Report message to a moderator

Re: [TENEO] Unable to get &quot;merge&quot; in hibernate list cascade using teneo properties [message #1236293 is a reply to message #1235316] Sun, 26 January 2014 21:25 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Minu,
I checked it again in the Teneo code, but this should work fine. Only if there is an JPA annotation on the model which
already set this cascade then it won't be used. Also it A.B is a containment then you should use another property.

gr. Martin

On 01/24/2014 04:38 AM, Minu martin wrote:
> I am using bidirectional relations between classes. I have a generic application and the entities are generated
> dynamically run time.
> I am trying to create an object of class A along with object of B(which needs to be created along with A) by saving A.
> Before performing create I need to do a hibernate merge operation.
> This is to avoid exception in case any instance of the request already exists in session as it is a generic application.
> But in this case while merging A object which contains B, I am getting a hibernate Exception ObjectNotFoundException for
> instance B. I realized that in the hbm file,the list cascade option does not have "merge", it only has
> "save-update,lock". Please let me know what settings I need to do to add "merge" also in the cascade of the list.
> I am using the teneo property - teneo.mapping.cascade_policy_on_non_containment = persist,merge,refresh
>
> Please find the hbm file generated by teneo below:
>
> <hibernate-mapping auto-import="false">
> <class entity-name="A" abstract="false" lazy="true" table="`a`"
> proxy="org.eclipse.emf.ecore.impl.DynamicEObjectImpl">
> <meta attribute="eclassName" inherit="false">A</meta>
> <meta attribute="epackage" inherit="false">com.znoo</meta>
> <cache usage="read-write"/>
> <id name="id" type="java.lang.String">
> <column not-null="true" unique="false" name="`id`"/>
> </id>
> <list name="b" lazy="true" cascade="save-update,lock">
> <cache usage="read-write"/>
> <key update="true">
> <column name="`b_a_id`" unique="false"/>
> </key>
> <list-index column="`a_b_idx`"/>
> <one-to-many entity-name="B"/>
> </list>
> </class>
> <class entity-name="B" abstract="false" lazy="true" table="`b`"
> proxy="org.eclipse.emf.ecore.impl.DynamicEObjectImpl">
> <meta attribute="eclassName" inherit="false">B</meta>
> <meta attribute="epackage" inherit="false">com.znoo</meta>
> <cache usage="read-write"/>
> <id name="id" type="java.lang.String">
> <column not-null="true" unique="false" name="`id`"/>
> </id>
> <many-to-one name="a" entity-name="A" lazy="proxy" cascade="merge,persist,save-update,lock,refresh"
> foreign-key="b_a" insert="false" update="false" not-null="false">
> <column not-null="false" unique="false" name="`b_a_id`"/>
> </many-to-one>
> </class>
> </hibernate-mapping>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [TENEO] Unable to get &quot;merge&quot; in hibernate list cascade using teneo properties [message #1244979 is a reply to message #1236293] Thu, 13 February 2014 05:44 Go to previous message
Minu martin is currently offline Minu martinFriend
Messages: 7
Registered: May 2013
Junior Member
Hi Martin,
We are not using JPA Annotations.
Do you mean to say that the list cascade option will have "merge" in addition to save-update,lock? This is not coming though.
Previous Topic:Split EClass definition between more than one resource
Next Topic:Eclipse UML Profiles Repository now available!
Goto Forum:
  


Current Time: Mon Aug 19 12:52:54 GMT 2019

Powered by FUDForum. Page generated in 0.02055 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top