Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » One-to-one references in Teneo 1.0.1
One-to-one references in Teneo 1.0.1 [message #423824] Tue, 07 October 2008 15:15 Go to next message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi,

I have two objects referencing each other. The reference in both of them
has lower bound and upper bound set to 1. Also, EOpposite is set to the
referenced object in both references.

With Teneo 1.0.0 in Eclipse 3.4.0 this worked fine, but after updating to
Eclipse 3.4.1 and Teneo 1.0.1 I get this error:

3819 [main] DEBUG org.hibernate.util.JDBCExceptionReporter - could not
insert: [ToolComposite] [insert into "myobject1" (e_id, e_version, "name",
"dtype") values (null, ?, ?, 'MyObjects')]
java.sql.SQLException: Attempt to insert null into a non-nullable column:
column: MYOBJECT2 table: myobject1 in statement [insert into "myobject1"
(e_id, e_version, "name", "dtype") values (null, ?, ?, 'MyObjects')]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
at
org.hibernate.id.insert.AbstractSelectingDelegate.performIns ert(AbstractSelectingDelegate.java:57)
at
org.hibernate.persister.entity.AbstractEntityPersister.inser t(AbstractEntityPersister.java:2186)
at
org.hibernate.persister.entity.AbstractEntityPersister.inser t(AbstractEntityPersister.java:2666)
at
org.hibernate.action.EntityIdentityInsertAction.execute(Enti tyIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:27 9)
at
org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:321)
at
org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:204)
at
org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:130)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:210)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:534)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :526)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :522)
at
org.eclipse.emf.teneo.hibernate.HbSessionWrapper.saveOrUpdat e(HbSessionWrapper.java:161)
at
[...]


A comparison of the database schemes generated by Teneo shows, that the
foreign key field is generated in the table for myobject1 in Teneo 1.0.1,
whereas the reference was the other way round in Teneo 1.0.0.

Did I find a new bug in Teneo here, or am I doing something wrong?

Roland
Re: One-to-one references in Teneo 1.0.1 [message #423839 is a reply to message #423824] Tue, 07 October 2008 19:18 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Roland,
Indeed the mapping of the one-to-one has changed since 1.0.0, before it was not working correctly in
some cases. You can influence the location of the foreign key by setting a
@OneToOne(mappedBy="otherside") on one side, then the foreign key will be placed on the other side.

Regarding your exception, I have seen this before in the following situation. Hibernate first saves
a set of objects with the foreign key fields set to null, even for fk fields which are mandatory.
Then when the objects are saved and the ids are determined an update is used to update the foreign
key fields. However often Hibernate is smart enough to do the persist in the correct order and then
this saving with null is not happening.

How does the mapping look like for the one-to-ones on both sides?

gr. Martin

Roland Brand wrote:
> Hi,
>
> I have two objects referencing each other. The reference in both of them
> has lower bound and upper bound set to 1. Also, EOpposite is set to the
> referenced object in both references.
>
> With Teneo 1.0.0 in Eclipse 3.4.0 this worked fine, but after updating
> to Eclipse 3.4.1 and Teneo 1.0.1 I get this error:
>
> 3819 [main] DEBUG org.hibernate.util.JDBCExceptionReporter - could not
> insert: [ToolComposite] [insert into "myobject1" (e_id, e_version,
> "name", "dtype") values (null, ?, ?, 'MyObjects')]
> java.sql.SQLException: Attempt to insert null into a non-nullable
> column: column: MYOBJECT2 table: myobject1 in statement [insert into
> "myobject1" (e_id, e_version, "name", "dtype") values (null, ?, ?,
> 'MyObjects')]
> at org.hsqldb.jdbc.Util.throwError(Unknown Source)
> at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
> at
> org.hibernate.id.insert.AbstractSelectingDelegate.performIns ert(AbstractSelectingDelegate.java:57)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.inser t(AbstractEntityPersister.java:2186)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.inser t(AbstractEntityPersister.java:2666)
>
> at
> org.hibernate.action.EntityIdentityInsertAction.execute(Enti tyIdentityInsertAction.java:71)
>
> at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:27 9)
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:321)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:204)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:130)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:210)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
>
> at
> org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:534)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :526)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :522)
> at
> org.eclipse.emf.teneo.hibernate.HbSessionWrapper.saveOrUpdat e(HbSessionWrapper.java:161)
>
> at [...]
>
>
> A comparison of the database schemes generated by Teneo shows, that the
> foreign key field is generated in the table for myobject1 in Teneo
> 1.0.1, whereas the reference was the other way round in Teneo 1.0.0.
>
> Did I find a new bug in Teneo here, or am I doing something wrong?
> Roland
>
>


--

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: One-to-one references in Teneo 1.0.1 [message #423877 is a reply to message #423839] Wed, 08 October 2008 15:00 Go to previous messageGo to next message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi Martin

> Regarding your exception, I have seen this before in the following
situation. Hibernate first saves
> a set of objects with the foreign key fields set to null, even for fk fields
which are mandatory.
> Then when the objects are saved and the ids are determined an update is used
to update the foreign
> key fields. However often Hibernate is smart enough to do the persist in the
correct order and then
> this saving with null is not happening.

This is exactly, what is happening. The exception is thrown, because the
fk field is declared as non-null.

> How does the mapping look like for the one-to-ones on both sides?

In the hibernate mapping, which is generated by EMF, I see, that the
relationship is declared as many-to-one in one direction and as one-to-one
in the other direction.

<subclass name="MyObject1" ...>
<many-to-one name="myobject2" entity-name="MyObject2"
cascade="merge,persist,save-update,lock,refresh" not-null="true"
lazy="false" insert="true" update="true"/>
</subclass>

<subclass name="MyObject2" ...>
<one-to-one name="myobjectt1" entity-name="MyObject1"
cascade="merge,persist,save-update,lock,refresh" lazy="false"
property-ref="myobject2" constrained="true"/>
</subclass>

Is this the expected mapping?

Thanks for your help.

Roland
Re: One-to-one references in Teneo 1.0.1 [message #423889 is a reply to message #423877] Thu, 09 October 2008 00:58 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Roland,
Yes this is the correct mapping for a non-pk one-to-one. You can influence where the many-to-one is
placed by setting a @OneToOne(mappedBy="theotherefeature") on one side, then the many-to-one will be
on the other side (which does not have the mappedBy defined).

gr. Martin

Roland Brand wrote:
> Hi Martin
>
>> Regarding your exception, I have seen this before in the following
> situation. Hibernate first saves
>> a set of objects with the foreign key fields set to null, even for fk
>> fields
> which are mandatory.
>> Then when the objects are saved and the ids are determined an update
>> is used
> to update the foreign
>> key fields. However often Hibernate is smart enough to do the persist
>> in the
> correct order and then
>> this saving with null is not happening.
>
> This is exactly, what is happening. The exception is thrown, because the
> fk field is declared as non-null.
>
>> How does the mapping look like for the one-to-ones on both sides?
>
> In the hibernate mapping, which is generated by EMF, I see, that the
> relationship is declared as many-to-one in one direction and as
> one-to-one in the other direction.
>
> <subclass name="MyObject1" ...>
> <many-to-one name="myobject2" entity-name="MyObject2"
> cascade="merge,persist,save-update,lock,refresh" not-null="true"
> lazy="false" insert="true" update="true"/>
> </subclass>
>
> <subclass name="MyObject2" ...>
> <one-to-one name="myobjectt1" entity-name="MyObject1"
> cascade="merge,persist,save-update,lock,refresh" lazy="false"
> property-ref="myobject2" constrained="true"/>
> </subclass>
>
> Is this the expected mapping?
>
> Thanks for your help.
>
> Roland
>
>


--

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: One-to-one references in Teneo 1.0.1 [message #423900 is a reply to message #423889] Thu, 09 October 2008 11:18 Go to previous messageGo to next message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi Martin

Adding the annotation you mentioned solved the problem for this special
case. But now a non-null reference field was generated in the database.
This leads to new problems when I try to save other objects derived from
the same super-class.

It looks like one-to-one references are possible with inheritance mapping
set to the default value SINGLE_TABLE.

Greetings, Roland
Re: One-to-one references in Teneo 1.0.1 [message #423901 is a reply to message #423900] Thu, 09 October 2008 11:28 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Roland,
Yes with single table, all columns from subtypes are made nullable...

gr. Martin

Roland Brand wrote:
> Hi Martin
>
> Adding the annotation you mentioned solved the problem for this special
> case. But now a non-null reference field was generated in the database.
> This leads to new problems when I try to save other objects derived from
> the same super-class.
>
> It looks like one-to-one references are possible with inheritance
> mapping set to the default value SINGLE_TABLE.
>
> Greetings, Roland
>
>


--

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: One-to-one references in Teneo 1.0.1 [message #423904 is a reply to message #423901] Thu, 09 October 2008 11:57 Go to previous messageGo to next message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Oh sorry, an important NOT is missing in my sentence. It seems like
one-to-one references are NOT possible in single table.

> Yes with single table, all columns from subtypes are made nullable...

This is, what I would have expected, but it is declared non-null in the
database.

Greets, Roland
Re: One-to-one references in Teneo 1.0.1 [message #423911 is a reply to message #423904] Thu, 09 October 2008 15:00 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Yes that makes a difference :-), does it work in case of join table inheritance strategy?
Because then this error is related on how the inheritance mapping is done and not on how hibernate
works with nullable references.

gr. Martin

Roland Brand wrote:
> Oh sorry, an important NOT is missing in my sentence. It seems like
> one-to-one references are NOT possible in single table.
>
>> Yes with single table, all columns from subtypes are made nullable...
>
> This is, what I would have expected, but it is declared non-null in the
> database.
>
> Greets, Roland
>


--

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: One-to-one references in Teneo 1.0.1 [message #423930 is a reply to message #423911] Fri, 10 October 2008 06:58 Go to previous message
Roland Brand is currently offline Roland BrandFriend
Messages: 42
Registered: July 2009
Member
Hi Martin

Yes it works with join tables. I have some other exceptions then, but I
don't know yet, if the new ones are related to teneo.

Greets, Roland
Previous Topic:[CDO] Duplicate ID problem – Can a CDO model have multiple non-containment references to an external
Next Topic:[CDO 1.0] CDOInvalidationNotification
Goto Forum:
  


Current Time: Sun Feb 23 02:47:14 GMT 2020

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

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

Back to the top