Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] containment: cannot update .. to null
[Teneo] containment: cannot update .. to null [message #1028640] Thu, 28 March 2013 14:43 Go to next message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
Hi,

We having some trouble when saving our objects into the database.. This is our model:

- Folder
-- 0..* documents: Document (containment: true, EOpposite: folder)

- Document
-- 1 folder : Folder (container: true, EOpposite: documents, annotation: @JoinColumn(name="FOLD_ID"))

The cascade option for containment is set to TRUE.

I'm trying to delete a Document from a Folder using a RemoveCommand. This works great till I'm trying to save.. Then I receive this error:

cannot update ("FOLD_ID") to NULL

It looks like it first tries to set the parent to NULL, but this is not allowed in the database..

How can I solve this?

Re: [Teneo] containment: cannot update .. to null [message #1028720 is a reply to message #1028640] Thu, 28 March 2013 16:47 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
Registered: July 2009
Senior Member
Hi Ricky,
It is a bit of a hibernate 'issue'. Can you try adding nullable=true to the join column annotation?

gr. Martin


On 03/28/2013 03:43 PM, Ricky de Klerck wrote:
> Hi,
>
> We having some trouble when saving our objects into the database.. This is our model:
>
> - Folder
> -- 0..* documents: Document (containment: true, EOpposite: folder)
>
> - Document
> -- 1 folder : Folder (container: true, EOpposite: documents, annotation: @JoinColumn(name="FOLD_ID"))
>
> The cascade option for containment is set to TRUE.
>
> I'm trying to delete a Document from a Folder using a RemoveCommand. This works great till I'm trying to save.. Then I
> receive this error:
>
> cannot update ("FOLD_ID") to NULL
>
> It looks like it first tries to set the parent to NULL, but this is not allowed in the database..
>
> How can I solve 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
Re: [Teneo] containment: cannot update .. to null [message #1032021 is a reply to message #1028720] Tue, 02 April 2013 13:33 Go to previous messageGo to next message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
Martin,

This doesn't make any difference.. Didn't you mean to set nullable to false btw? (I tried both false and true)
Re: [Teneo] containment: cannot update .. to null [message #1032026 is a reply to message #1032021] Tue, 02 April 2013 13:36 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
Registered: July 2009
Senior Member
Hi Ricky,
I ment nullable to true so that it is nullable, hmm, can you post the relevant hbm here? Also the generated ddl/schema
update to check that indeed the column is not-nullable?

gr. Martin

On 04/02/2013 03:33 PM, Ricky de Klerck wrote:
> Martin,
>
> This doesn't make any difference.. Didn't you mean to set nullable to false btw? (I tried both false and true)


--

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] containment: cannot update .. to null [message #1032138 is a reply to message #1032021] Tue, 02 April 2013 16:04 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 367
Registered: December 2010
Location: Germany
Senior Member
Hi

This could be related to discussion we had a while ago:
http://www.eclipse.org/forums/index.php/m/899992/?srch=CDO%2FHibernate

If I am correct, then the optional attribute in the many-to-one element overrides the nullable attribute in the join-column element.

Hope this helps.

Christoph

Re: [Teneo] containment: cannot update .. to null [message #1032992 is a reply to message #1032026] Wed, 03 April 2013 18:31 Go to previous messageGo to next message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
Martin,

The problem here is that we can't change the database. We have to modify the model in such a way the parent isn't set to NULL..

and Christophe..

When I use the @ManyToOne annotation, everything is overridden right? I don't want this and thats exactly the reason I used the EOpposite. So I hope there's another solution..
Re: [Teneo] containment: cannot update .. to null [message #1033613 is a reply to message #1028640] Thu, 04 April 2013 12:39 Go to previous messageGo to next message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
In addition.. this is the generated mapping for the Folder reference in a Document:

<many-to-one name="folder" entity-name="Folder" lazy="false" insert="true" update="true" not-null="false">
  <column not-null="false" unique="false" name="FOLD_ID"/>
</many-to-one>


I don't know why the property not-null is set to false, because it is a 1-1 relation..

It tries to set this to NULL before it actually removes the Document. Is there a way to prevent this from happening?
Re: [Teneo] containment: cannot update .. to null [message #1033653 is a reply to message #1033613] Thu, 04 April 2013 13:34 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
Registered: July 2009
Senior Member
Hi Ricky,
I don't know directly why not-null is false... I would need to debug with the model to see why hibernate does this and
more importantly to determine what can be done against it. Bi-directional 1-1 associations are always quite tricky...

I can try to make an example model myself or otherwise if you have a focused/down-sized model then you can send it to
me. Will try to take a look at it in/over the weekend..

gr. Martin

On 04/04/2013 02:39 PM, Ricky de Klerck wrote:
> In addition.. this is the generated mapping for the Folder reference in a Document:
>
> <many-to-one name="folder" entity-name="Folder" lazy="false" insert="true" update="true" not-null="false">
> <column not-null="false" unique="false" name="FOLD_ID"/>
> </many-to-one>
>
> I don't know why the property not-null is set to false, because it is a 1-1 relation..
>
> It tries to set this to NULL before it actually removes the Document. Is there a way to prevent this from happening?


--

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] containment: cannot update .. to null [message #1033707 is a reply to message #1033653] Thu, 04 April 2013 14:46 Go to previous message
Ricky de Klerck is currently offline Ricky de Klerck
Messages: 295
Registered: January 2011
Senior Member
Martin,

It is not a Bi directional 1-1 assocation but many to one. A folder can have zero or more documents but a document always belongs to one parent. When deleting a document from the list (documents) in a folder, the document itself should be deleted as well.

I will try to see if I can make a downsized example tomorrow.
Previous Topic:How to parse an XMI file to SQL
Next Topic:Problems try to use Offline example code
Goto Forum:
  


Current Time: Wed Oct 22 12:20:11 GMT 2014

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

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