Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo/Hibernate] eReference, containment, cascade all and deleting gone wrong
[Teneo/Hibernate] eReference, containment, cascade all and deleting gone wrong [message #783816] Thu, 26 January 2012 14:19 Go to next message
Matthias Kloppenborg is currently offline Matthias KloppenborgFriend
Messages: 17
Registered: April 2010
Junior Member
Hello everyone,

i am new to Teneo and got a problem which i could not solve on my own.

If i delete a Procedure object, the Variables don't get deleted, though
it's a containment reference.

I created a minimal example, hope one of you can see where things go wrong.

Thank you!

----------

Relevant part of ecore model:

<eClassifiers xsi:type="ecore:EClass" name="Procedure">
<eStructuralFeature xsi:type="ecore:EReference"
name="variables" upperBound="-1"
eType="#//Variable" containment="true"/>
</eClassifiers>

<eClassifiers xsi:type="ecore:EClass" name="Variable">
<eStructuralFeatures xsi:type="ecore:EAttribute"
name="name" eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>

----------

Relevant options are set.

PersistenceOptions.CASCADE_POLICY_ON_CONTAINMENT, "ALL"

----------

Part of annotations.xml:

<eclass name="Procedure">
<property name="variables">
<one-to-many mapped-by="Variable" indexed="false"/>
</property>
</eclass>

<eclass name="Variable">
</eclass>

----------

Parts of source code:

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String hqlDelete = "delete Project.Procedure where name = :name ";
int deletedEntities = session.createQuery( hqlDelete ).setString(
"name", "procedure" ).executeUpdate();
tx.commit();
session.close();

----------
Re: [Teneo/Hibernate] eReference, containment, cascade all and deleting gone wrong [message #783869 is a reply to message #783816] Thu, 26 January 2012 16:11 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Matthias,
I guess it does not work because you use a delete query instead of going through the session. Another reason could be
that there is a join table for the one-to-many, so the join table records get deleted but not the child records.

Can you post the hbm? You can get it by calling dataStore.getMappingXML() after initializing it.

gr. Martin

On 01/26/2012 03:19 PM, Matthias Kloppenborg wrote:
> Hello everyone,
>
> i am new to Teneo and got a problem which i could not solve on my own.
>
> If i delete a Procedure object, the Variables don't get deleted, though it's a containment reference.
>
> I created a minimal example, hope one of you can see where things go wrong.
>
> Thank you!
>
> ----------
>
> Relevant part of ecore model:
>
> <eClassifiers xsi:type="ecore:EClass" name="Procedure">
> <eStructuralFeature xsi:type="ecore:EReference"
> name="variables" upperBound="-1"
> eType="#//Variable" containment="true"/>
> </eClassifiers>
>
> <eClassifiers xsi:type="ecore:EClass" name="Variable">
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="name" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
>
> ----------
>
> Relevant options are set.
>
> PersistenceOptions.CASCADE_POLICY_ON_CONTAINMENT, "ALL"
>
> ----------
>
> Part of annotations.xml:
>
> <eclass name="Procedure">
> <property name="variables">
> <one-to-many mapped-by="Variable" indexed="false"/>
> </property>
> </eclass>
>
> <eclass name="Variable">
> </eclass>
>
> ----------
>
> Parts of source code:
>
> Session session = sessionFactory.openSession();
> Transaction tx = session.beginTransaction();
> String hqlDelete = "delete Project.Procedure where name = :name ";
> int deletedEntities = session.createQuery( hqlDelete ).setString( "name", "procedure" ).executeUpdate();
> tx.commit();
> session.close();
>
> ----------
>
>


--

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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo/Hibernate] eReference, containment, cascade all and deleting gone wrong [message #788789 is a reply to message #783869] Thu, 02 February 2012 08:13 Go to previous messageGo to next message
Matthias Kloppenborg is currently offline Matthias KloppenborgFriend
Messages: 17
Registered: April 2010
Junior Member
Hi Martin,

thanks for your help. I don't know why i didn't use the delete method of
the session. Now it works, thank you for your help.

Greetings
Matthias

P.S.: Can you give me a tip for good literature about teneo?

Am 26.01.2012 17:11, schrieb Martin Taal:
> Hi Matthias,
> I guess it does not work because you use a delete query instead of going
> through the session. Another reason could be that there is a join table
> for the one-to-many, so the join table records get deleted but not the
> child records.
>
> Can you post the hbm? You can get it by calling
> dataStore.getMappingXML() after initializing it.
>
> gr. Martin
>
> On 01/26/2012 03:19 PM, Matthias Kloppenborg wrote:
>> Hello everyone,
>>
>> i am new to Teneo and got a problem which i could not solve on my own.
>>
>> If i delete a Procedure object, the Variables don't get deleted,
>> though it's a containment reference.
>>
>> I created a minimal example, hope one of you can see where things go
>> wrong.
>>
>> Thank you!
>>
>> ----------
>>
>> Relevant part of ecore model:
>>
>> <eClassifiers xsi:type="ecore:EClass" name="Procedure">
>> <eStructuralFeature xsi:type="ecore:EReference"
>> name="variables" upperBound="-1"
>> eType="#//Variable" containment="true"/>
>> </eClassifiers>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="Variable">
>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>> name="name" eType="ecore:EDataType
>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>> </eClassifiers>
>>
>> ----------
>>
>> Relevant options are set.
>>
>> PersistenceOptions.CASCADE_POLICY_ON_CONTAINMENT, "ALL"
>>
>> ----------
>>
>> Part of annotations.xml:
>>
>> <eclass name="Procedure">
>> <property name="variables">
>> <one-to-many mapped-by="Variable" indexed="false"/>
>> </property>
>> </eclass>
>>
>> <eclass name="Variable">
>> </eclass>
>>
>> ----------
>>
>> Parts of source code:
>>
>> Session session = sessionFactory.openSession();
>> Transaction tx = session.beginTransaction();
>> String hqlDelete = "delete Project.Procedure where name = :name ";
>> int deletedEntities = session.createQuery( hqlDelete ).setString(
>> "name", "procedure" ).executeUpdate();
>> tx.commit();
>> session.close();
>>
>> ----------
>>
>>
>
>
Re: [Teneo/Hibernate] eReference, containment, cascade all and deleting gone wrong [message #794746 is a reply to message #788789] Thu, 09 February 2012 16:53 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Matthias,
Sorry I missed your ps, the wiki has extensive information:
http://wiki.eclipse.org/Teneo/Hibernate

gr. Martin

On 02/02/2012 09:13 AM, Matthias Kloppenborg wrote:
> Hi Martin,
>
> thanks for your help. I don't know why i didn't use the delete method of the session. Now it works, thank you for your
> help.
>
> Greetings
> Matthias
>
> P.S.: Can you give me a tip for good literature about teneo?
>
> Am 26.01.2012 17:11, schrieb Martin Taal:
>> Hi Matthias,
>> I guess it does not work because you use a delete query instead of going
>> through the session. Another reason could be that there is a join table
>> for the one-to-many, so the join table records get deleted but not the
>> child records.
>>
>> Can you post the hbm? You can get it by calling
>> dataStore.getMappingXML() after initializing it.
>>
>> gr. Martin
>>
>> On 01/26/2012 03:19 PM, Matthias Kloppenborg wrote:
>>> Hello everyone,
>>>
>>> i am new to Teneo and got a problem which i could not solve on my own.
>>>
>>> If i delete a Procedure object, the Variables don't get deleted,
>>> though it's a containment reference.
>>>
>>> I created a minimal example, hope one of you can see where things go
>>> wrong.
>>>
>>> Thank you!
>>>
>>> ----------
>>>
>>> Relevant part of ecore model:
>>>
>>> <eClassifiers xsi:type="ecore:EClass" name="Procedure">
>>> <eStructuralFeature xsi:type="ecore:EReference"
>>> name="variables" upperBound="-1"
>>> eType="#//Variable" containment="true"/>
>>> </eClassifiers>
>>>
>>> <eClassifiers xsi:type="ecore:EClass" name="Variable">
>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>>> name="name" eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>>> </eClassifiers>
>>>
>>> ----------
>>>
>>> Relevant options are set.
>>>
>>> PersistenceOptions.CASCADE_POLICY_ON_CONTAINMENT, "ALL"
>>>
>>> ----------
>>>
>>> Part of annotations.xml:
>>>
>>> <eclass name="Procedure">
>>> <property name="variables">
>>> <one-to-many mapped-by="Variable" indexed="false"/>
>>> </property>
>>> </eclass>
>>>
>>> <eclass name="Variable">
>>> </eclass>
>>>
>>> ----------
>>>
>>> Parts of source code:
>>>
>>> Session session = sessionFactory.openSession();
>>> Transaction tx = session.beginTransaction();
>>> String hqlDelete = "delete Project.Procedure where name = :name ";
>>> int deletedEntities = session.createQuery( hqlDelete ).setString(
>>> "name", "procedure" ).executeUpdate();
>>> tx.commit();
>>> session.close();
>>>
>>> ----------
>>>
>>>
>>
>>
>


--

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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:Research Papers on CDO
Next Topic:Collaborative Modeling
Goto Forum:
  


Current Time: Thu Apr 25 23:53:55 GMT 2024

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

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

Back to the top