Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] How to reference an object by its Composite Key
[Teneo] How to reference an object by its Composite Key [message #425253] Thu, 20 November 2008 22:55 Go to next message
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
Hi All

I have an object called LensAddOn with a composite key. (char+int)
I have another object called LensOptionToAddOn. It is a join table with
a composite key made up of an int that is FK related to another table
plus the composite key that refers to Lens Add On.

So in short:

LensAddOn
int A PK
char B PK

LensOption
int O PK

LensRelation
int A PK
char B PK
int O PK

How can I create the class to use for the LensRelation tables?
I have a embeddable object for use in LensAddon. Should I re-use that
embeddable object in the embeddable composite key for LensRelation?

Any help or examples are much appreciated. Even just an example of
creating a 1->Many where where the one side is a composite key could be
helpful.


Thanks,

Jason Henriksen
Re: [Teneo] How to reference an object by its Composite Key [message #425255 is a reply to message #425253] Fri, 21 November 2008 00:44 Go to previous messageGo to next message
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
I'm into answering my own questions today. The trick is to use the
@JoinColumns attribute (notice the trailing 's')


Here's the relevant XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:ecore='http://www.eclipse.org/emf/2002/Ecore'
xmlns:com.vsp.supplier.model.lens='http://lens.model.supplier.vsp.com'
targetNamespace='http://lens.model.supplier.vsp.com'
ecore:nsPrefix='com.vsp.supplier.model.lens'
ecore:package='com.vsp.supplier.model.lens'
elementFormDefault='qualified'
>
<xsd:include schemaLocation='AllFiles.xsd'/>


<xsd:complexType name="LensAddOnOptionToLensOptionRelationCompositeKey">

<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Embeddable</xsd:appinfo>
</xsd:annotation>

<xsd:sequence>
<xsd:element name="key"
type="xsd:IDREF"
ecore:reference="com.vsp.supplier.model.lens:LensAddOnOption ">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@ManyToOne
@JoinColumns ({
@JoinColumn(name="PRODUCT_CD", <!-- col name in DB -->
referencedColumnName = "productCode"), <!-- remote field name -->
@JoinColumn(name="PRODUCT_SVCOPT_CD", <!-- DB -->
referencedColumnName = "serviceOption")<!-- Java -->
})
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>

<!-- the other side of this object's relationship -->
<xsd:attribute
name="optionObject"
type="xsd:IDREF" ecore:reference="com.vsp.supplier.model.lens:LensOption"
>
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@ManyToOne
@JoinColumn(name="OPTION_CD")
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>

</xsd:complexType>

</xsd:schema>



Martin, are you writing a book on Teneo yet?
If not, sign me up.


Jason Henriksen



jason henriksen wrote:
> Hi All
>
> I have an object called LensAddOn with a composite key. (char+int)
> I have another object called LensOptionToAddOn. It is a join table with
> a composite key made up of an int that is FK related to another table
> plus the composite key that refers to Lens Add On.
>
> So in short:
>
> LensAddOn
> int A PK
> char B PK
>
> LensOption
> int O PK
>
> LensRelation
> int A PK
> char B PK
> int O PK
>
> How can I create the class to use for the LensRelation tables?
> I have a embeddable object for use in LensAddon. Should I re-use that
> embeddable object in the embeddable composite key for LensRelation?
>
> Any help or examples are much appreciated. Even just an example of
> creating a 1->Many where where the one side is a composite key could be
> helpful.
>
>
> Thanks,
>
> Jason Henriksen
Re: [Teneo] How to reference an object by its Composite Key [message #425263 is a reply to message #425255] Fri, 21 November 2008 10:31 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Jason,
It is great that you answer your own questions and even more that you post them back :-).

No book yet, although I must say that you and other users have brought up some pretty complex
mapping examples which are solvable with annotations. It would be nice to combine those together in
one document one day...

gr. Martin

jason henriksen wrote:
>
> I'm into answering my own questions today. The trick is to use the
> @JoinColumns attribute (notice the trailing 's')
>
>
> Here's the relevant XSD:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema
> xmlns:xsd='http://www.w3.org/2001/XMLSchema'
> xmlns:ecore='http://www.eclipse.org/emf/2002/Ecore'
> xmlns:com.vsp.supplier.model.lens='http://lens.model.supplier.vsp.com'
> targetNamespace='http://lens.model.supplier.vsp.com'
> ecore:nsPrefix='com.vsp.supplier.model.lens'
> ecore:package='com.vsp.supplier.model.lens'
> elementFormDefault='qualified'
> >
> <xsd:include schemaLocation='AllFiles.xsd'/>
>
>
> <xsd:complexType name="LensAddOnOptionToLensOptionRelationCompositeKey">
>
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Embeddable</xsd:appinfo>
> </xsd:annotation>
>
> <xsd:sequence>
> <xsd:element name="key"
> type="xsd:IDREF"
> ecore:reference="com.vsp.supplier.model.lens:LensAddOnOption ">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @ManyToOne
> @JoinColumns ({
> @JoinColumn(name="PRODUCT_CD", <!-- col name in DB -->
> referencedColumnName = "productCode"), <!-- remote field name -->
> @JoinColumn(name="PRODUCT_SVCOPT_CD", <!-- DB -->
> referencedColumnName = "serviceOption")<!-- Java -->
> })
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
> </xsd:sequence>
>
> <!-- the other side of this object's relationship -->
> <xsd:attribute
> name="optionObject"
> type="xsd:IDREF"
> ecore:reference="com.vsp.supplier.model.lens:LensOption"
> >
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @ManyToOne
> @JoinColumn(name="OPTION_CD")
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
>
> </xsd:complexType>
>
> </xsd:schema>
>
>
>
> Martin, are you writing a book on Teneo yet?
> If not, sign me up.
>
>
> Jason Henriksen
>
>
>
> jason henriksen wrote:
>> Hi All
>>
>> I have an object called LensAddOn with a composite key. (char+int)
>> I have another object called LensOptionToAddOn. It is a join table
>> with a composite key made up of an int that is FK related to another
>> table plus the composite key that refers to Lens Add On.
>>
>> So in short:
>>
>> LensAddOn
>> int A PK
>> char B PK
>>
>> LensOption
>> int O PK
>>
>> LensRelation
>> int A PK
>> char B PK
>> int O PK
>>
>> How can I create the class to use for the LensRelation tables?
>> I have a embeddable object for use in LensAddon. Should I re-use that
>> embeddable object in the embeddable composite key for LensRelation?
>>
>> Any help or examples are much appreciated. Even just an example of
>> creating a 1->Many where where the one side is a composite key could
>> be helpful.
>>
>>
>> Thanks,
>>
>> Jason Henriksen


--

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:Rose Importer Patch and Question
Next Topic:Issue with chunking in CDO
Goto Forum:
  


Current Time: Wed Feb 26 16:08:30 GMT 2020

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

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

Back to the top