Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community Forums[Teneo] How to reference an object by its Composite Key
https://www.eclipse.org/forums/index.php/mv/msg/135404/425253/#msg_425253
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]]>Jason Henriksen2008-11-20T22:55:35-00:00Re: [Teneo] How to reference an object by its Composite Key
https://www.eclipse.org/forums/index.php/mv/msg/135404/425255/#msg_425255
@JoinColumns attribute (notice the trailing 's')
<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]]>Jason Henriksen2008-11-21T00:44:33-00:00Re: [Teneo] How to reference an object by its Composite Key
https://www.eclipse.org/forums/index.php/mv/msg/135404/425263/#msg_425263
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