Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO/Hibernate] Defining not-nullable EReferences
[CDO/Hibernate] Defining not-nullable EReferences [message #899992] Fri, 03 August 2012 11:27 Go to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 347
Registered: December 2010
Location: Germany
Senior Member
Hello

I am creating a demo with CDO/Hibernate to see if all our requirements in the generated database tables can be met. So far I am doing well except for two small issues I ran into with EReferences that should be set to "not null" in the database.

To achieve this I tried to set the annotations via xml like this:
<eclass name="Assignment">
	...
	<ereference name="project">
		<join-column name="project_e_id" nullable="false"/>
	</ereference>
	...
</eclass>

The "nullable" attribute seems to be ignored.
(I'm sure the file is read correctly, because other constraints on attributes work: i.e. <column nullable="false" unique="true"/>).

Environment:
- CDO 4.1.0.v20120612
- TENEO 2.0.0.v20120709
- MySQL Server 5.5.18

Related, but different: If the name attribute is omitted in the join-column element this will lead to an exception:

[ERROR] Unable to read XML
org.hibernate.InvalidMappingException: Unable to read XML
	at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:106)
	at org.hibernate.cfg.Configuration.add(Configuration.java:477)
...

Caused by: org.xml.sax.SAXParseException: Attribute "name" is required and must be specified for element type "column".
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)

This is only the case for join-column elements and not for column elements. This should not be required imho.

Would you like bug reports on these issues, or am I missing something?

Greetings
Christoph
Re: [CDO/Hibernate] Defining not-nullable EReferences [message #900417 is a reply to message #899992] Mon, 06 August 2012 23:29 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
Hi Christophe,
Sorry for the later answer, I did a testcase and issue for this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=386607

After the next build the name attribute is not needed anymore.

For your specific issue, set nullable="true" will help (I should have seen that right away...).

gr. Martin

On 08/03/2012 01:27 PM, Christoph Keimel wrote:
> Hello
>
> I am creating a demo with CDO/Hibernate to see if all our requirements in the generated database tables can be met. So
> far I am doing well except for two small issues I ran into with EReferences that should be set to "not null" in the
> database.
>
> To achieve this I tried to set the annotations via xml like this:
> <eclass name="Assignment">
> ...
> <ereference name="project">
> <join-column name="project_e_id" nullable="false"/>
> </ereference>
> ...
> </eclass>
> The "nullable" attribute seems to be ignored.
> (I'm sure the file is read correctly, because other constraints on attributes work: i.e. <column nullable="false"
> unique="true"/>).
>
> Environment:
> - CDO 4.1.0.v20120612
> - TENEO 2.0.0.v20120709
> - MySQL Server 5.5.18
>
> Related, but different: If the name attribute is omitted in the join-column element this will lead to an exception:
>
> [ERROR] Unable to read XML
> org.hibernate.InvalidMappingException: Unable to read XML
> at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:106)
> at org.hibernate.cfg.Configuration.add(Configuration.java:477)
> ...
>
> Caused by: org.xml.sax.SAXParseException: Attribute "name" is required and must be specified for element type "column".
> at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
> at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
> This is only the case for join-column elements and not for column elements. This should not be required imho.
>
> Would you like bug reports on these issues, or am I missing something?
>
> 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] Defining not-nullable EReferences [message #900496 is a reply to message #900417] Tue, 07 August 2012 09:59 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 347
Registered: December 2010
Location: Germany
Senior Member
Hi Martin,

thanks for the reply. What I would like to achieve is that the foreign key column (here project_e_id) is "not null". With attributes, this is achieved with (verified):
<eattribute name="name">
	<column nullable="false"/>
</eattribute>

With references this should be (I think):
<ereference name="project">
	<join-column name="project_e_id" nullable="false"/>
</ereference>

Maybe this has to do with the setting of the property "teneo.mapping.join_table_for_non_contained_associations"? I have set this to "false".

(I also use the attribute unique="true" with <eattribute> and <ereference>. This works in both cases.)

Greetings
Christoph
Re: [CDO/Hibernate] Defining not-nullable EReferences [message #900499 is a reply to message #900496] Tue, 07 August 2012 10:03 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
He Christoph,
Auch, I am the one who is confused here..:-) Let me retest it the other way around.
I assume the ereference is not mandatory in ecore right?

gr. martin

On 08/07/2012 11:59 AM, Christoph Keimel wrote:
> Hi Martin,
>
> thanks for the reply. What I would like to achieve is that the foreign key column (here project_e_id) is "not null".
> With attributes, this is achieved with (verified): <eattribute name="name">
> <column nullable="false"/>
> </eattribute>
> With references this should be (I think):
> <ereference name="project">
> <join-column name="project_e_id" nullable="false"/>
> </ereference>
> Maybe this has to do with the setting of the property "teneo.mapping.join_table_for_non_contained_associations"? I have
> set this to "false".
>
> (I also use the attribute unique="true" with <eattribute> and <ereference>. This works in both cases.)
>
> 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] Defining not-nullable EReferences [message #900543 is a reply to message #900499] Tue, 07 August 2012 13:12 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 347
Registered: December 2010
Location: Germany
Senior Member
Hi Martin,

I'm using xcore to define the model. I. e.:
class Project extends CompanyElement {
	refers Assignment[] assignements opposite project
}

class Assignment {
	refers Project project opposite assignements
	refers Employee employee opposite assignements
}

I also tried "refers Project[1] project", to make it mandatory, but that did not have an effect on the column definition (nor on the generated classes). Is there another way to define mandatory attributes/references in ecore/xcore?

Greetings
Christoph
Re: [CDO/Hibernate] Defining not-nullable EReferences [message #900637 is a reply to message #900543] Tue, 07 August 2012 21:30 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
Hi Christophe,
I asked Ed Merks to reply on your question.

Regarding the persistence xml, instead of setting the nullable on the join column you have to use a many-to-one tag in
this case (the many-to-one again overrides the join-column one, bit unlogical but that's the way it works now...).

Like here:
<?xml version="1.0" encoding="utf-8"?>
<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/issues/bz386607">
<eclass name="Bar">
<ereference name="foo">
<many-to-one optional="false"/>
</ereference>
</eclass>
</epackage>
</persistence-mapping>

gr. Martin


On 08/07/2012 03:12 PM, Christoph Keimel wrote:
> Hi Martin,
>
> I'm using xcore to define the model. I. e.:
> class Project extends CompanyElement {
> refers Assignment[] assignements opposite project
> }
>
> class Assignment {
> refers Project project opposite assignements
> refers Employee employee opposite assignements
> }
> I also tried "refers Project[1] project", to make it mandatory, but that did not have an effect on the column definition
> (nor on the generated classes). Is there another way to define mandatory attributes/references in ecore/xcore?
>
> 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] Defining not-nullable EReferences [message #900698 is a reply to message #900637] Wed, 08 August 2012 08:26 Go to previous message
Christoph Keimel is currently offline Christoph Keimel
Messages: 347
Registered: December 2010
Location: Germany
Senior Member
Hi Martin,

thanks! That's the solution Smile

Greetings,
Christoph
Previous Topic:[CDO 4.1]Security Manager Problem
Next Topic:How to call an EOperation in atl program?
Goto Forum:
  


Current Time: Tue Sep 02 21:23:20 GMT 2014

Powered by FUDForum. Page generated in 0.02045 seconds