|
Re: [CDO/Hibernate] NOT NULL constraint on EReference with EOpposite [message #940257 is a reply to message #940047] |
Thu, 11 October 2012 13:14 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Christoph,
To check where the 'error' is, is the optional="false" not picked up by the generated mapping?
gr. Martin
On 10/11/2012 11:08 AM, Christoph Keimel wrote:
> Hi Martin
>
> thanks for taking the time to have a look at bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=391134.
>
> I have a question extending the topic:
>
> Using this test model:
> class TestElement {
> String name
> refers OtherElement[] others opposite ref
> }
> class OtherElement {
> String name
> refers TestElement[1] ref opposite others
> }
> If I change the annotation as suggested to
> <eclass name="OtherElement">
> <ereference name="ref">
> <many-to-one optional="false"/>
> <join-column nullable="true" name="testelement_e_id"/>
> </ereference>
> </eclass>
> The <many-to-one optional="false"/> does not have an effect. By this I mean, that I can persist an instance a of
> OtherElement where a.ref is null.
>
> The column testelement_e_id does not have a not null constraint, as expected do to the join-column definition. What I
> did expect was for Hibernate to throw it's own exception do to the many-to-one definition. Would you expect this to be
> the case?
>
> Is there a way to enforce a reference with an opposite to be non null using either Hibernate or Database mechanisms?
>
> Greetings
> Christoph
>
> P.S. I know I can use Ecore Validation to check this on the client side, but I would like to have an additional server
> side back up check enforcing this similar to other not null or unique constraints.
--
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: [CDO/Hibernate] NOT NULL constraint on EReference with EOpposite [message #941112 is a reply to message #941049] |
Fri, 12 October 2012 07:51 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Christoph,
Strange, I don't fully understand the mapping, why the many-to-many... Can you send me the ecore model?
gr. Martin
On 10/12/2012 09:10 AM, Christoph Keimel wrote:
> Hi Martin
>
> this is the relevant part of the generated mapping for the two classes:
>
> <class entity-name="TestElement" abstract="false" lazy="true" discriminator-value="TestElement" table="`testelement`">
> <meta attribute="eclassName" inherit="false">TestElement</meta>
> ...
> <property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false"
> type="java.lang.String">
> <column not-null="false" unique="false" name="`name`"/>
> </property>
> <list name="others" table="`testelement_others`" lazy="true" cascade="persist,merge,refresh,save-update,lock">
> <key update="true">
> <column name="`testelement_e_id`" unique="false"/>
> </key>
> <list-index column="`testelement_others_idx`"/>
> <many-to-many entity-name="OtherElement" unique="true">
> <column name="`otherelement_e_id`" unique="false"/>
> </many-to-many>
> </list>
> </class>
> <class entity-name="OtherElement" abstract="false" lazy="true" discriminator-value="OtherElement" table="`otherelement`">
> <meta attribute="eclassName" inherit="false">OtherElement</meta>
> ...
> <property name="name" lazy="false" insert="true" update="true" not-null="true" unique="false" type="java.lang.String">
> <column not-null="true" unique="false" name="`name`"/>
> </property>
> <many-to-one name="ref" entity-name="TestElement" lazy="false" foreign-key="otherelement_ref" insert="true"
> update="true" not-null="false"/>
> </class>
>
> Seams to me as if <many-to-one optional="false"/> and <join-column nullable="true"/> from the configuration boil down to
> a single attribute in the hbm mapping: <many-to-one not-null="false"/> where the joincolum definition wins over the
> many-to-one definition.
>
> Greetings
> Christoph
--
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: [CDO/Hibernate] NOT NULL constraint on EReference with EOpposite [message #941297 is a reply to message #941112] |
Fri, 12 October 2012 11:22 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Christoph,
I did some testing and the conclusion is indeed that hibernate does not enforce the constraint, it is left to the
database, which in this case allows nulls...
So no other option than to check on the EMF side..
gr. Martin
On 10/12/2012 09:51 AM, Martin Taal wrote:
> Hi Christoph,
> Strange, I don't fully understand the mapping, why the many-to-many... Can you send me the ecore model?
>
> gr. Martin
>
>
> On 10/12/2012 09:10 AM, Christoph Keimel wrote:
>> Hi Martin
>>
>> this is the relevant part of the generated mapping for the two classes:
>>
>> <class entity-name="TestElement" abstract="false" lazy="true" discriminator-value="TestElement" table="`testelement`">
>> <meta attribute="eclassName" inherit="false">TestElement</meta>
>> ...
>> <property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false"
>> type="java.lang.String">
>> <column not-null="false" unique="false" name="`name`"/>
>> </property>
>> <list name="others" table="`testelement_others`" lazy="true" cascade="persist,merge,refresh,save-update,lock">
>> <key update="true">
>> <column name="`testelement_e_id`" unique="false"/>
>> </key>
>> <list-index column="`testelement_others_idx`"/>
>> <many-to-many entity-name="OtherElement" unique="true">
>> <column name="`otherelement_e_id`" unique="false"/>
>> </many-to-many>
>> </list>
>> </class>
>> <class entity-name="OtherElement" abstract="false" lazy="true" discriminator-value="OtherElement" table="`otherelement`">
>> <meta attribute="eclassName" inherit="false">OtherElement</meta>
>> ...
>> <property name="name" lazy="false" insert="true" update="true" not-null="true" unique="false"
>> type="java.lang.String">
>> <column not-null="true" unique="false" name="`name`"/>
>> </property>
>> <many-to-one name="ref" entity-name="TestElement" lazy="false" foreign-key="otherelement_ref" insert="true"
>> update="true" not-null="false"/>
>> </class>
>>
>> Seams to me as if <many-to-one optional="false"/> and <join-column nullable="true"/> from the configuration boil down to
>> a single attribute in the hbm mapping: <many-to-one not-null="false"/> where the joincolum definition wins over the
>> many-to-one definition.
>>
>> Greetings
>> Christoph
>
>
--
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03789 seconds