Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Annotations required to support 2 associations between two classes
[Teneo] Annotations required to support 2 associations between two classes [message #499457] Sun, 22 November 2009 18:55 Go to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I have 2 classes instrument and underlying. An underlying is a type
instrument. An instrument may have many underlying, each of these
underlying is also an instrument. So I have underlying *..1 instrument
and underlying 1..1 instrument. The customer expects to see a generated
database with an instrument table and a underlying table with 2 foreign
keys, one for the one to many from instrument to underlying and one for
the one to one due to underlying being a sub type of instrument. How do
I achieve this result using XSD annotations?

Thx.

David
Re: [Teneo] Annotations required to support 2 associations between two classes [message #499460 is a reply to message #499457] Sun, 22 November 2009 19:32 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
I would think that this should happen automatically if you use the joined inheritance strategy.
http://www.elver.org/hibernate/inheritance.html

Have you tried that?

If you want to control naming you should use JoinColumn and the PrimaryKeyJoinColumn annotation. There are some examples
here:
http://www.elver.org/hibernate/ejb3_format.html
http://www.elver.org/download/xmlsamples/Claim.xsd

gr. Martin

David Wynter wrote:
> Hi,
>
> I have 2 classes instrument and underlying. An underlying is a type
> instrument. An instrument may have many underlying, each of these
> underlying is also an instrument. So I have underlying *..1 instrument
> and underlying 1..1 instrument. The customer expects to see a generated
> database with an instrument table and a underlying table with 2 foreign
> keys, one for the one to many from instrument to underlying and one for
> the one to one due to underlying being a sub type of instrument. How do
> I achieve this result using XSD annotations?
>
> Thx.
>
> David


--

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: [Teneo] Annotations required to support 2 associations between two classes [message #500597 is a reply to message #499460] Thu, 26 November 2009 22:45 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I use JOINED inheritance mapping. But I tried to put the join for the
super class to the subclass like so

<xsd:complexType name="Instrument">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="1" type="xsd:anyURI"
name="underlyingdetail" ecore:reference="mddb:Underlying" >
<xsd:annotation>
<xsd:appinfo
source="teneo.jpa">@JoinColumn(name="underlyingdetail")</xsd:appinfo >
</xsd:annotation>
</xsd:element>
....

Then the ManyToOne from the subclass to the superclass like so

<xsd:complexType name="Underlying">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element ecore:reference="mddb:Instrument" minOccurs="0"
maxOccurs="unbounded" name="underlying" type="xsd:anyURI">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@ManyToOne(optional="true")
@JoinColumn(name="instrument")
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
....

And end up with

Exception in thread "main"
org.eclipse.emf.teneo.annotations.mapper.StoreMappingExcepti on: The
feature/eclass underlying/Underlying should be a OneToMany but it
already has a ManyToMany, OneToOne or ManyToOne annotation
at
org.eclipse.emf.teneo.annotations.mapper.OneToManyReferenceA nnotator.annotate(OneToManyReferenceAnnotator.java:59)
at
org.eclipse.emf.teneo.hibernate.annotations.HbOneToManyRefer enceAnnotator.annotate(HbOneToManyReferenceAnnotator.java:62 )
at
org.eclipse.emf.teneo.annotations.mapper.EFeatureAnnotator.a nnotate(EFeatureAnnotator.java:195)
at
org.eclipse.emf.teneo.annotations.mapper.EClassAnnotator.ann otate(EClassAnnotator.java:270)
at
org.eclipse.emf.teneo.hibernate.annotations.HbEClassAnnotato r.annotate(HbEClassAnnotator.java:57)
at
org.eclipse.emf.teneo.annotations.mapper.AnnotationGenerator .processPackage(AnnotationGenerator.java:168)
at
org.eclipse.emf.teneo.annotations.mapper.AnnotationGenerator .map(AnnotationGenerator.java:136)
at
org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:177)
at
org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:73)
at
org.eclipse.emf.teneo.hibernate.HbDataStore.mapEPackages(HbD ataStore.java:711)
at
org.eclipse.emf.teneo.hibernate.HbSessionDataStore.mapModel( HbSessionDataStore.java:160)
at
org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ e(HbSessionDataStore.java:77)

The error is clear but it still leaves me trying to work out how I can
have and Underlying as a subclass of Instrument and also allow an
Instrument to have many Underlying

thx.

David







Martin Taal wrote:
> Hi David,
> I would think that this should happen automatically if you use the
> joined inheritance strategy.
> http://www.elver.org/hibernate/inheritance.html
>
> Have you tried that?
>
> If you want to control naming you should use JoinColumn and the
> PrimaryKeyJoinColumn annotation. There are some examples here:
> http://www.elver.org/hibernate/ejb3_format.html
> http://www.elver.org/download/xmlsamples/Claim.xsd
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> I have 2 classes instrument and underlying. An underlying is a type
>> instrument. An instrument may have many underlying, each of these
>> underlying is also an instrument. So I have underlying *..1 instrument
>> and underlying 1..1 instrument. The customer expects to see a
>> generated database with an instrument table and a underlying table
>> with 2 foreign keys, one for the one to many from instrument to
>> underlying and one for the one to one due to underlying being a sub
>> type of instrument. How do I achieve this result using XSD annotations?
>>
>> Thx.
>>
>> David
>
>
Re: [Teneo] Annotations required to support 2 associations between two classes [message #500609 is a reply to message #500597] Fri, 27 November 2009 06:02 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
See comments inline.

gr. Martin

David Wynter wrote:
> Hi,
>
> I use JOINED inheritance mapping. But I tried to put the join for the
> super class to the subclass like so
>
> <xsd:complexType name="Instrument">
> <xsd:sequence>
> <xsd:element minOccurs="0" maxOccurs="1" type="xsd:anyURI"
> name="underlyingdetail" ecore:reference="mddb:Underlying" >
MT>> If an Instrument has many underlying then I would expect maxOccurs="unbounded" here. If you want this reference to
share the foreign key column with the reference on the other side then you have to set ecore:opposite also here (or on
the other reference). If you don't use ecore:opposite then you need to set the JoinColumn annotation on both sides with
the same JoinColum name (if you want sharing of the same foreign key column).

> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@JoinColumn(name="underlyingdetail")</xsd:appinfo >
> </xsd:annotation>
> </xsd:element>
> ....
>
> Then the ManyToOne from the subclass to the superclass like so
>
> <xsd:complexType name="Underlying">
MT>> if an Underlying is a subtype of Instrument I would expect an xsd:extension somewhere

> <xsd:sequence minOccurs="0" maxOccurs="1">
> <xsd:element ecore:reference="mddb:Instrument" minOccurs="0"
> maxOccurs="unbounded" name="underlying" type="xsd:anyURI">
MT>> If an Instrument has many Underlying and an Underlying at most 1 Instrument then I would expect maxOccurs="1"
MT>> Setting maxOccurs="1" will also solve the exception below. With maxOccurs="unbounded" you can only use
OneToMany/ManyToMany annotations (as the exception text says).
MT>> A side remark, I would expect the name of the element to be instrument as it refers to the instrument type

> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @ManyToOne(optional="true")
MT>> the @ManyToOne(optional=true) is not required if minOccurs="0" as Teneo will add it automatically
> @JoinColumn(name="instrument")
MT>> If you change the name of the element to instrument then this JoinColumn is not needed (Teneo will then use the
instrument name).
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
> ....
>
> And end up with
>
> Exception in thread "main"
> org.eclipse.emf.teneo.annotations.mapper.StoreMappingExcepti on: The
> feature/eclass underlying/Underlying should be a OneToMany but it
> already has a ManyToMany, OneToOne or ManyToOne annotation
> at
> org.eclipse.emf.teneo.annotations.mapper.OneToManyReferenceA nnotator.annotate(OneToManyReferenceAnnotator.java:59)
>
> at
> org.eclipse.emf.teneo.hibernate.annotations.HbOneToManyRefer enceAnnotator.annotate(HbOneToManyReferenceAnnotator.java:62 )
>
> at
> org.eclipse.emf.teneo.annotations.mapper.EFeatureAnnotator.a nnotate(EFeatureAnnotator.java:195)
>
> at
> org.eclipse.emf.teneo.annotations.mapper.EClassAnnotator.ann otate(EClassAnnotator.java:270)
>
> at
> org.eclipse.emf.teneo.hibernate.annotations.HbEClassAnnotato r.annotate(HbEClassAnnotator.java:57)
>
> at
> org.eclipse.emf.teneo.annotations.mapper.AnnotationGenerator .processPackage(AnnotationGenerator.java:168)
>
> at
> org.eclipse.emf.teneo.annotations.mapper.AnnotationGenerator .map(AnnotationGenerator.java:136)
>
> at
> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:177)
>
> at
> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:73)
>
> at
> org.eclipse.emf.teneo.hibernate.HbDataStore.mapEPackages(HbD ataStore.java:711)
>
> at
> org.eclipse.emf.teneo.hibernate.HbSessionDataStore.mapModel( HbSessionDataStore.java:160)
>
> at
> org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ e(HbSessionDataStore.java:77)
>
>
> The error is clear but it still leaves me trying to work out how I can
> have and Underlying as a subclass of Instrument and also allow an
> Instrument to have many Underlying
>
> thx.
>
> David
>
>
>
>
>
>
>
> Martin Taal wrote:
>> Hi David,
>> I would think that this should happen automatically if you use the
>> joined inheritance strategy.
>> http://www.elver.org/hibernate/inheritance.html
>>
>> Have you tried that?
>>
>> If you want to control naming you should use JoinColumn and the
>> PrimaryKeyJoinColumn annotation. There are some examples here:
>> http://www.elver.org/hibernate/ejb3_format.html
>> http://www.elver.org/download/xmlsamples/Claim.xsd
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> I have 2 classes instrument and underlying. An underlying is a type
>>> instrument. An instrument may have many underlying, each of these
>>> underlying is also an instrument. So I have underlying *..1
>>> instrument and underlying 1..1 instrument. The customer expects to
>>> see a generated database with an instrument table and a underlying
>>> table with 2 foreign keys, one for the one to many from instrument to
>>> underlying and one for the one to one due to underlying being a sub
>>> type of instrument. How do I achieve this result using XSD annotations?
>>>
>>> Thx.
>>>
>>> David
>>
>>


--

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
Previous Topic:[CDO] scalability test problem
Next Topic:Problems to locate a resource
Goto Forum:
  


Current Time: Wed Apr 24 19:20:24 GMT 2024

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

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

Back to the top