Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] On delete child, parent id is set to null before actual delete statement
[Teneo] On delete child, parent id is set to null before actual delete statement [message #1063125] Wed, 12 June 2013 12:10 Go to next message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
Hi,

I'm struggling with this all day, so hope I hope someone can help me..

This is my (simplified) model:

- Parent
-- childs : Child 0..* (containment:true (cascade ALL), opposite:parent)
- Child
-- parent : Parent 1 (teneo.jpa: @JoinColumn(name="PARENT_ID") )

When I delete a Child from 'childs' it tries to set 'parent' to NULL, but it has a NOT NULL constraint in the DB so it raises an error. After this update, the delete statement is called.

How can I change the behaviour so the delete statement is called right away?

I read something about setting inverse but I don't know where and how to set this. I have no teneo.jpa on childs, because of the opposite...

Hope someone can help, thanks in advance!

[Updated on: Wed, 12 June 2013 12:11]

Report message to a moderator

Re: [Teneo] On delete child, parent id is set to null before actual delete statement [message #1063228 is a reply to message #1063125] Wed, 12 June 2013 18:03 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Ricky,
You have to set a OneToMany annotation on the childs efeature with mappedBy attribute set to parent, in addition indexed
should be set to false:
@OneToMany(inverse=true, indexed=false)

This should create the inverse="true".

See these posts/links:
https://forum.hibernate.org/viewtopic.php?p=2383090
https://bugs.eclipse.org/bugs/show_bug.cgi?id=242479

gr. Martin

On 06/12/2013 02:10 PM, Ricky de Klerck wrote:
> Hi,
>
> I'm struggling with this all day, so hope I hope someone can help me..
>
> This is my (simplified) model:
>
> - Parent
> -- childs : Child 0..* (containment:true (cascade ALL), opposite:parent)
> - Child
> -- parent : Parent 1 (teneo.jpa: @JoinColumn(name="PARENT_ID")
>
> When I delete a Child from 'childs' it tries to set 'parent' to NULL, but it has a NOT NULL constraint in the DB so it
> raises an error. After this update, the delete statement is called.
>
> How can I change the behaviour so the delete statement is called right away?
>
> I read something about setting inverse but I don't know where and how to set this. I have no teneo.jpa on childs,
> because of the opposite...
>
> Hope someone can help, thanks in advance!


--

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] On delete child, parent id is set to null before actual delete statement [message #1063460 is a reply to message #1063228] Thu, 13 June 2013 08:48 Go to previous messageGo to next message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
Thanks for your answer, but I can't get it to work..

I deleted the opposite and added this to the childs reference:

@OneToMany(mappedBy="parent", indexed=false)


But now it can't find a column..

This is the generated mapping:

<bag name="childs" inverse="true" lazy="true" cascade="all,delete-orphan">
  <key update="true">
    <column name="DCMNTSQLSTTMNT_DCMNTLYTS_DSS_D" unique="false"/>
  </key>
  <one-to-many entity-name="Child"/>
</bag>


This is the error:

Missing column: DCMNTSQLSTTMNT_DCMNTLYTS_DSS_D in CHILD


What am I doing wrong here? It seems like the mappedBy isn't done correctly..
Re: [Teneo] On delete child, parent id is set to null before actual delete statement [message #1063476 is a reply to message #1063460] Thu, 13 June 2013 09:27 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
It seems that the DCMNTSQLSTTMNT_DCMNTLYTS_DSS_D column is not created on the other side. How does the many-to-one on
the other side look like?

gr. Martin

On 06/13/2013 10:48 AM, Ricky de Klerck wrote:
> Thanks for your answer, but I can't get it to work..
>
> I deleted the opposite and added this to the childs reference:
> @OneToMany(mappedBy="parent", indexed=false)
>
> But now it can't find a column..
>
> This is the generated mapping:
>
>
> <bag name="childs" inverse="true" lazy="true" cascade="all,delete-orphan">
> <key update="true">
> <column name="DCMNTSQLSTTMNT_DCMNTLYTS_DSS_D" unique="false"/>
> </key>
> <one-to-many entity-name="Child"/>
> </bag>
>
>
> This is the error:
>
>
> Missing column: DCMNTSQLSTTMNT_DCMNTLYTS_DSS_D in CHILD
>
>
> What am I doing wrong here? It seems like the mappedBy isn't done correctly..
>


--

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] On delete child, parent id is set to null before actual delete statement [message #1063483 is a reply to message #1063476] Thu, 13 June 2013 09:40 Go to previous messageGo to next message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
That is correct, because I manually defined a column. This is the mapping generated for the manyToOne:

<many-to-one name="parent" entity-name="Parent" lazy="false" insert="false" update="false" not-null="true">
  <column not-null="true" unique="false" name="DOSS_ID"/>
</many-to-one>


I suppose it should reference to DOSS_ID and not to DCMNTSQLSTTMNT_DCMNTLYTS_DSS_D.
Re: [Teneo] On delete child, parent id is set to null before actual delete statement [message #1063485 is a reply to message #1063483] Thu, 13 June 2013 09:41 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Can you try this: next to the OneToMany you should also have a JoinColumn annotation (on that side) like this:
@JoinColumn(name="DOSS_ID")

gr. Martin

On 06/13/2013 11:40 AM, Ricky de Klerck wrote:
> That is correct, because I manually defined a column. This is the mapping generated for the manyToOne:
>
>
> <many-to-one name="parent" entity-name="Parent" lazy="false" insert="false" update="false" not-null="true">
> <column not-null="true" unique="false" name="DOSS_ID"/>
> </many-to-one>
>
>
> I suppose it should reference to DOSS_ID and not to DCMNTSQLSTTMNT_DCMNTLYTS_DSS_D.


--

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] On delete child, parent id is set to null before actual delete statement [message #1063491 is a reply to message #1063485] Thu, 13 June 2013 09:57 Go to previous messageGo to next message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
Ok, that works! But isn't it possible to set the opposite AND the inverse = true? Now I manually have to add the Child to childs AND set the parent in child. Or am I wrong?
Re: [Teneo] On delete child, parent id is set to null before actual delete statement [message #1063627 is a reply to message #1063491] Thu, 13 June 2013 14:29 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Ricky,
Normally these bi-directional references are handled by EMF (so EMF sets the other automatically for you). In the
database a reference is always stored on one side but queryable from both sides.

gr. Martin

On 06/13/2013 11:57 AM, Ricky de Klerck wrote:
> Ok, that works! But isn't it possible to set the opposite AND the inverse = true? Now I manually have to add the Child
> to childs AND set the parent in child. Or am I wrong?


--

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] On delete child, parent id is set to null before actual delete statement [message #1064263 is a reply to message #1063125] Tue, 18 June 2013 13:38 Go to previous messageGo to next message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
You're right, I removed the opposite but everything works when I turn it back on.

I have still one question though.. In our structure we define folders and subfolders. A folder is a root (no parent) or subfolder. When I want to make a folder root, I simply set the parent to null and save. But, because of the cascade, the folder is actually deleted from the database! How can I prevent this?

[Updated on: Tue, 18 June 2013 13:38]

Report message to a moderator

Re: [Teneo] On delete child, parent id is set to null before actual delete statement [message #1064280 is a reply to message #1064263] Tue, 18 June 2013 14:16 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Ricky,
I think the best solution is to create a new instance for the root and copy the content over to that new root and save it.

gr. Martin

On 06/18/2013 03:38 PM, Ricky de Klerck wrote:
> You're right, I removed the opposite but everything works when I turned it back on.
>
> I have still one question though.. In our structure we define folders and subfolders. A folder is a root (no parent) or
> subfolder. When I want to make a folder root, I simply set the parent to null and save. But, because of the cascade, the
> folder is actually deleted from the database! How can I prevent this?


--

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
Previous Topic:Newbie question: not all classes of the ecore available in the editor
Next Topic:JSON Resources from EMF ?
Goto Forum:
  


Current Time: Mon Sep 22 12:17:58 GMT 2014

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

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