Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » JPA Annotation for Composite Foregin Key
JPA Annotation for Composite Foregin Key [message #89012] Wed, 11 July 2007 16:48 Go to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I have composite key in Object A i.e. (type,id,version,node). Object B has
relation ship to A. So when I use Teneo to create HBM file and then create
DDL script from it , I need those 4 fields be added in table B (with
convention as A_id,A_type ...etc.) and foreign key is created in table B
with reference to table A.

I tried that with @JoinColumns annotations and Teneo gave me exception
sayings is not supported. Whats the mechansim to represent composite
foregin keys ?
Re: JPA Annotation for Composite Foregin Key [message #89028 is a reply to message #89012] Wed, 11 July 2007 16:59 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
What is the exception and how does your annotation look like?
And can you show (part of) the ecore describing this relation?

gr. Martin

Vaibhav Kulkarni wrote:
> I have composite key in Object A i.e. (type,id,version,node). Object B
> has relation ship to A. So when I use Teneo to create HBM file and then
> create DDL script from it , I need those 4 fields be added in table B
> (with convention as A_id,A_type ...etc.) and foreign key is created in
> table B with reference to table A.
>
> I tried that with @JoinColumns annotations and Teneo gave me exception
> sayings is not supported. Whats the mechansim to represent composite
> foregin keys ?
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #89101 is a reply to message #89028] Wed, 11 July 2007 20:57 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I get following exception :

Caused by: org.eclipse.emf.teneo.hibernate.mapper.MappingException:
Unsupported multiple join columns, EReference/subclass
at
org.eclipse.emf.teneo.hibernate.mapper.ManyToOneMapper.proce ss(ManyToOneMapper.java:64)
at
org.eclipse.emf.teneo.hibernate.mapper.FeatureMapper.process PAnnotatedEReference(FeatureMapper.java:161)
at
org.eclipse.emf.teneo.hibernate.mapper.FeatureMapper.process (FeatureMapper.java:97)
at
org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processF eature(EntityMapper.java:553)
at
org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processF eatures(EntityMapper.java:438)
at
org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processE ntity(EntityMapper.java:335)
at
org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.processPAClass(HibernateMappingGenerator.java:194)
at
org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.processPersistentClasses(HibernateMappingGenerator.java :162)
at
org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.generate(HibernateMappingGenerator.java:124)
... 7 more

I am cut pasting annotations in ecore ..

<eClassifiers xsi:type="ecore:EClass" name="RelationshipClass">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="relationname"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="subclass"
eType="#//Subclass">
<eAnnotations source="teneo.jpa">
<details key="appinfo"
value=" @JoinColumns({@JoinColumn(name=&quot;owning_id&quot; ,
referencedColumnName=&quot;id&quot;),@JoinColumn(nam e=&quot;owning_ver&quot;,
referencedColumnName=&quot;version&quot;),@JoinColum n(name=&quot;owning_type&quot;,
referencedColumnName=&quot;type&quot;)})"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>

RelationshipClass has 0 to 1 relationship to class named "Subclass". This
Subclass has its primary key as id, type and version. So I want to add
this 3 columns in RelationshipClass table with customized names (as shown
above) as foreign keys.


is this right annotation to be used to solve composite forign key issue ?
Re: JPA Annotation for Composite Foregin Key [message #89116 is a reply to message #89101] Wed, 11 July 2007 21:11 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Yes, I see, multiple join columns on a many-to-one are not yet supported. I am currently working on
a new release. If you enter a bugzilla for this then I can try to incorporate this in this next
release (within a week).

gr. Martin

Vaibhav Kulkarni wrote:
> I get following exception :
>
> Caused by: org.eclipse.emf.teneo.hibernate.mapper.MappingException:
> Unsupported multiple join columns, EReference/subclass
> at
> org.eclipse.emf.teneo.hibernate.mapper.ManyToOneMapper.proce ss(ManyToOneMapper.java:64)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.FeatureMapper.process PAnnotatedEReference(FeatureMapper.java:161)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.FeatureMapper.process (FeatureMapper.java:97)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processF eature(EntityMapper.java:553)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processF eatures(EntityMapper.java:438)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processE ntity(EntityMapper.java:335)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.processPAClass(HibernateMappingGenerator.java:194)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.processPersistentClasses(HibernateMappingGenerator.java :162)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.generate(HibernateMappingGenerator.java:124)
>
> ... 7 more
>
> I am cut pasting annotations in ecore ..
>
> <eClassifiers xsi:type="ecore:EClass" name="RelationshipClass">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="relationname"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="subclass"
> eType="#//Subclass">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo"
> value=" @JoinColumns({@JoinColumn(name=&quot;owning_id&quot; ,
> referencedColumnName=&quot;id&quot;),@JoinColumn(nam e=&quot;owning_ver&quot;,
> referencedColumnName=&quot;version&quot;),@JoinColum n(name=&quot;owning_type&quot;,
> referencedColumnName=&quot;type&quot;)})"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
>
> RelationshipClass has 0 to 1 relationship to class named "Subclass".
> This Subclass has its primary key as id, type and version. So I want to
> add this 3 columns in RelationshipClass table with customized names (as
> shown above) as foreign keys.
>
>
> is this right annotation to be used to solve composite forign key issue ?
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #89131 is a reply to message #89101] Wed, 11 July 2007 21:15 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I have similar issue for composite primary keys when
@Inheritance(strategy="JOINED") is used between concrete parent class and
its concrete sub class. I want only composite parent keys are added in
subclass table as a foreign keys to parent class. Parent table should have
only properties in Parent class and Child table should have only
properties in Child subclass.

I get following exception :

Caused by: org.hibernate.MappingException: Foreign key
(FK6F2A564026128853:relationshipclass [subclass_subclass_id])) must have
same number of columns as the referenced primary key (subclass
[id,type,version])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.jav a:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.jav a:73)
Re: JPA Annotation for Composite Foregin Key [message #89146 is a reply to message #89131] Wed, 11 July 2007 21:57 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080706000602050300090804
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

I have a testcase which covers this case as well as a one-to-many using a composite-key. I have
attached the ecore and the resulting hbm so you can see if there are any differences with your approach.

gr. martin

Vaibhav Kulkarni wrote:
> I have similar issue for composite primary keys when
> @Inheritance(strategy="JOINED") is used between concrete parent class
> and its concrete sub class. I want only composite parent keys are added
> in subclass table as a foreign keys to parent class. Parent table should
> have only properties in Parent class and Child table should have only
> properties in Child subclass.
>
> I get following exception :
>
> Caused by: org.hibernate.MappingException: Foreign key
> (FK6F2A564026128853:relationshipclass [subclass_subclass_id])) must have
> same number of columns as the referenced primary key (subclass
> [id,type,version])
> at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.jav a:90)
> at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.jav a:73)
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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

--------------080706000602050300090804
Content-Type: text/xml;
name="JoinColumnsTest$1_mysql_s_o_hibernate.hbm.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="JoinColumnsTest$1_mysql_s_o_hibernate.hbm.xml"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- Generated by Teneo on Wed Jul 11 23:53:48 CEST 2007 -->
<hibernate-mapping auto-import="false">
<class name=" org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.im pl.PersonImpl " entity-name="Person" abstract="false" lazy="false" table="`person`">
<meta attribute="eclassName">Person</meta>
<meta attribute="epackage"> http://www.eclipse.org/emf/teneo/samples/emf/annotations/joi ncolumns</meta>
<composite-id class=" org.eclipse.emf.teneo.samples.emf.annotations.compositeid.Pe rsonID " mapped="true">
<key-property name="firstName" type="java.lang.String">
<column not-null="true" unique="false" name="`firstname`"/>
</key-property>
<key-property name="lastName" type="java.lang.String">
<column not-null="true" unique="false" name="`lastname`"/>
</key-property>
</composite-id>
<version name="myversion" column="myversion" access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
<meta attribute="syntheticVersion">true</meta>
</version>
</class>
<joined-subclass name=" org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.im pl.ParentImpl " entity-name="Parent" abstract="false" lazy="false" extends="Person" table="`parent`">
<meta attribute="eclassName">Parent</meta>
<meta attribute="epackage"> http://www.eclipse.org/emf/teneo/samples/emf/annotations/joi ncolumns</meta>
<key>
<column name="`person_firstname`"/>
<column name="`person_lastname`"/>
</key>
<list name="children" lazy="true" cascade="merge,persist,save-update,lock,refresh">
<key update="true">
<column name="`myparentfirstname`" not-null="false" unique="false"/>
<column name="`myparentlastname`" not-null="false" unique="false"/>
</key>
<list-index column="`parent_children_idx`"/>
<one-to-many entity-name="Child"/>
</list>
</joined-subclass>
<joined-subclass name=" org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.im pl.ChildImpl " entity-name="Child" abstract="false" lazy="false" extends="Person" table="`child`">
<meta attribute="eclassName">Child</meta>
<meta attribute="epackage"> http://www.eclipse.org/emf/teneo/samples/emf/annotations/joi ncolumns</meta>
<key>
<column name="`person_firstname`"/>
<column name="`person_lastname`"/>
</key>
</joined-subclass>
</hibernate-mapping>
--------------080706000602050300090804
Content-Type: text/xml;
name="jc.ecore"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="jc.ecore"

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="joincolumns"
nsURI=" http://www.eclipse.org/emf/teneo/samples/emf/annotations/joi ncolumns" nsPrefix="joincolumns">
<eClassifiers xsi:type="ecore:EClass" name="Parent" eSuperTypes="#//Person">
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//Child">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value=" @JoinColumns({@JoinColumn(name=&quot;myParentFirstName&a mp;quot; referencedColumnName=&quot;firstName&quot;),&#xA ;&#x9;@JoinColumn(name=&quot;myParentLastName&qu ot; referencedColumnName=&quot;lastName&quot;)})"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Child" eSuperTypes="#//Person"/>
<eClassifiers xsi:type="ecore:EClass" name="Person">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value=" @IdClass(org.eclipse.emf.teneo.samples.emf.annotations.compo siteid.PersonID) "/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="firstName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Id"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="lastName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Id"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>

--------------080706000602050300090804--
Re: JPA Annotation for Composite Foregin Key [message #89591 is a reply to message #89146] Thu, 12 July 2007 21:19 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I have noticed few differences as well as I am confused with the test case
result and DDL it generates.

1) I am using @EmbeddedId and @Embeddeable and test case uses @IdClass.
Hopefullly they should work the same way. It works for me for one class.
But as soon as I extend that class it doesnt.

2) Test ecore shows 0 to many relation ship between Parent and Child. That
means it should create join table 4 columns (parent_firstname,
parent_lastname, child_firstname , child_lastname) .. Its doing some thing
different. Its instead adding these columns into child table . If relation
ships is shown between Parent and Child , then shouldnt it create tables
accordingly ?

3) If Parent has foreign key to Person , then why its adding Persons
primary key to Child table. One can go from Child to Parent and then to
Person to pick up all colums from Parent .

I will try to see if @IdClass works but I do see with representing these
relationships in the data base.
Re: JPA Annotation for Composite Foregin Key [message #89605 is a reply to message #89591] Thu, 12 July 2007 21:27 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000406030309050207020308
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

See my comments inline.

gr. Martin

Vaibhav Kulkarni wrote:
> I have noticed few differences as well as I am confused with the test
> case result and DDL it generates.
>
> 1) I am using @EmbeddedId and @Embeddeable and test case uses @IdClass.
> Hopefullly they should work the same way. It works for me for one class.
> But as soon as I extend that class it doesnt.
MT>> I attached also a testcase which has embeddedid. Unfortunately it is simpler
than the joincolumn one.

>
> 2) Test ecore shows 0 to many relation ship between Parent and Child.
> That means it should create join table 4 columns (parent_firstname,
> parent_lastname, child_firstname , child_lastname) .. Its doing some
> thing different. Its instead adding these columns into child table . If
> relation ships is shown between Parent and Child , then shouldnt it
> create tables accordingly ?
MT>> It is a relation without a join table, so then the foreign key is placed
in the child table.
With a join table it would look differently but I did not test that case.

>
> 3) If Parent has foreign key to Person , then why its adding Persons
> primary key to Child table. One can go from Child to Parent and then to
> Person to pick up all colums from Parent .
MT>> Also child inherits from Person, therefore there is a foreign key from the child table
to the person table.

>
> I will try to see if @IdClass works but I do see with representing these
> relationships in the data base.
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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

--------------000406030309050207020308
Content-Type: text/xml;
name="embeddedid.ecore"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="embeddedid.ecore"

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="embeddedid"
nsURI=" http://www.eclipse.org/emf/teneo/samples/emf/annotations/emb eddedid" nsPrefix="embeddedid">
<eClassifiers xsi:type="ecore:EClass" name="Name">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Embeddable"/>
</eAnnotations>
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="Name"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="firstName" unique="false"
lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="firstName"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="lastName" unique="false"
lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="lastName"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Person">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="Person"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="name" lowerBound="1" eType="#//Name"
containment="true" resolveProxies="false">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@EmbeddedId"/>
</eAnnotations>
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="name"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="address" unique="false"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Lob"/>
</eAnnotations>
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="address"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>

--------------000406030309050207020308
Content-Type: text/xml;
name="EmbeddedId.xsd"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="EmbeddedId.xsd"

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace=" http://www.eclipse.org/emf/teneo/samples/emf/annotations/emb eddedid"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:this=" http://www.eclipse.org/emf/teneo/samples/emf/annotations/emb eddedid">

<xsd:complexType name="Person">
<xsd:sequence>
<xsd:element name="name" type="this:Name">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@EmbeddedId</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="address" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Lob</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Name">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Embeddable</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="firstName" type="xsd:string"/>
<xsd:element name="lastName" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>

</xsd:schema>
--------------000406030309050207020308
Content-Type: text/xml;
name="EmbeddedIdAction_mysql_s_o_hibernate.hbm.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="EmbeddedIdAction_mysql_s_o_hibernate.hbm.xml"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- Generated by Teneo on Thu Jul 12 19:26:02 CEST 2007 -->
<hibernate-mapping auto-import="false">
<class name=" org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.imp l.PersonImpl " entity-name="Person" abstract="false" lazy="false" table="`person`">
<meta attribute="eclassName">Person</meta>
<meta attribute="epackage"> http://www.eclipse.org/emf/teneo/samples/emf/annotations/emb eddedid</meta>
<composite-id name="name" class=" org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.imp l.NameImpl ">
<key-property name="firstName" type="java.lang.String">
<column not-null="true" unique="false" name="`firstname`"/>
</key-property>
<key-property name="lastName" type="java.lang.String">
<column not-null="true" unique="false" name="`lastname`"/>
</key-property>
</composite-id>
<version name="e_version" column="e_version" access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="address" lazy="false" insert="true" update="true" not-null="false" unique="false" type="text">
<column not-null="false" unique="false" name="`address`"/>
</property>
</class>
</hibernate-mapping>
--------------000406030309050207020308--
Re: JPA Annotation for Composite Foregin Key [message #89967 is a reply to message #89605] Tue, 17 July 2007 10:15 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I have summarized issues after doing some more evaluation around JPA
annotations.

1) Join table is not created for many to many or many to one non contained
associations even though Teneo persistence option of
"JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS=true" WHEN primary key is
composed of more than one columns. When I changed Primary Key to contain
only one column , it worked well & I did not had to specify @JoinTable
annotations. As I beleive this option is created to avoid specifying
explicit @JoinTable annotation. Pls fix this and test it using composite
primary key expresedd using @IdClass or @Embedeable/@EmbeddedId

2) If JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS option is set to "true"
and @JoinColumns annotations is used then it does create DDL and adds
foreign key columns in the table for class representing other side of the
relation ship . I think this is covered in your Person/Child/Parent test
case where columns are added in Child table even though "children"
relationship is present in Parent class. This works with both single
column PK as well as composite PK. But does than mean @JoinColumns
annotations take precedence over JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS
?

3) Same thing true for INHERITANCE_MAPPING=JOINED settings. It works for
single column PK but not for composite PK. Once composite PK is defined it
fails to add one column in the table (representing subclass) for every
column in PK of parent class. Once fixed it also needs to be tested with
JPA annotation of
@Inheritance(strategy="JOINED") to check if it gives same result as
INHERITANCE_MAPPING=JOINED settings.

4) Came across below exception when attempt was made to customize inverse
column names using @JoinTable annotation.

Caused by: org.xml.sax.SAXParseException: Attribute "update" must be
declared for element type "many-to-many".
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. createSAXParseException(Unknown
Source)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. error(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(Unknown
Source)

Heres is annotation :

"appinfo", "@JoinTable(name=\"parent_child\",
joinColumns=@JoinColumn(name=\"parent_FirstName\"
referencedColumnName=\"firstName\"), " +
"inverseJoinColumns=@JoinColumn(name=\"child_FirstName\"
referencedColumnName=\"firstName\") )"
Re: JPA Annotation for Composite Foregin Key [message #90168 is a reply to message #89967] Tue, 17 July 2007 15:25 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Vaibhav,
See my comments in line.

Vaibhav Kulkarni wrote:
> I have summarized issues after doing some more evaluation around JPA
> annotations.
>
> 1) Join table is not created for many to many or many to one non
> contained associations even though Teneo persistence option of
> "JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS=true" WHEN primary key is
> composed of more than one columns. When I changed Primary Key to contain
> only one column , it worked well & I did not had to specify @JoinTable
> annotations. As I beleive this option is created to avoid specifying
> explicit @JoinTable annotation. Pls fix this and test it using composite
> primary key expresedd using @IdClass or @Embedeable/@EmbeddedId
MT>> Yes I am looking into this.

Btw, to me (as a non-native english speaker) the phrase 'Pls fix this and test it' sounds kind of
commandeering, probably you don't mean it that way...

>
> 2) If JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS option is set to "true"
> and @JoinColumns annotations is used then it does create DDL and adds
> foreign key columns in the table for class representing other side of
> the relation ship . I think this is covered in your Person/Child/Parent
> test case where columns are added in Child table even though "children"
> relationship is present in Parent class. This works with both single
> column PK as well as composite PK. But does than mean @JoinColumns
> annotations take precedence over
> JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS ?
MT>> No the option should take precedence, if it doesn't then it is a bug. As I am looking into this
topic (of composite-ids) right now I will also check it.

> 3) Same thing true for INHERITANCE_MAPPING=JOINED settings. It works
> for single column PK but not for composite PK. Once composite PK is
> defined it fails to add one column in the table (representing subclass)
> for every column in PK of parent class. Once fixed it also needs to be
> tested with JPA annotation of @Inheritance(strategy="JOINED") to check
> if it gives same result as INHERITANCE_MAPPING=JOINED settings.
MT> The person-child testcase I sent you earlier covers this case, all test cases are run for single
and joined inheritance mapping.

>
> 4) Came across below exception when attempt was made to customize
> inverse column names using @JoinTable annotation.
MT>> I will adapt the testcase to also include a jointable with a composite-id, hopefully this
exception will also appear there.

>
> Caused by: org.xml.sax.SAXParseException: Attribute "update" must be
> declared for element type "many-to-many".
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. createSAXParseException(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. error(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(Unknown
> Source)
>
> Heres is annotation :
>
> "appinfo", "@JoinTable(name=\"parent_child\",
> joinColumns=@JoinColumn(name=\"parent_FirstName\"
> referencedColumnName=\"firstName\"), " +
>
> "inverseJoinColumns=@JoinColumn(name=\"child_FirstName\"
> referencedColumnName=\"firstName\") )"
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #90260 is a reply to message #90168] Wed, 18 July 2007 00:25 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
Martin

Thanks and I apologize if you interpret it that way. Ofcourse i didnt mean
it that way.

Thanks again and you being a great help.
Re: JPA Annotation for Composite Foregin Key [message #90409 is a reply to message #90260] Wed, 18 July 2007 11:23 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Vaibhav,
Thanks, no problem, regarding the four topics you mention:
1) the testcase I added yesterday to your bugzilla covers this case, this works now afaics.
2) I tested this case but I could not replicate this issue
3) the testcase covers this also and it seemed to work.
4) I was able to reproduce this error, it has been solved in cvs.

Let me know if the testcase I added to the bugzilla covers your case (or not ofcourse).

This will be in the next build (today or tomorrow).

gr. Martin

Vaibhav Kulkarni wrote:
> Martin
> Thanks and I apologize if you interpret it that way. Ofcourse i didnt
> mean it that way.
> Thanks again and you being a great help.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #91274 is a reply to message #90409] Mon, 23 July 2007 09:55 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
Martin

I just verified 2007/07/18 release and it works. Thanks for fixing it.

I have one more question. I have composite primary key with 4 columns but
in some cases I just want to add id column in the join table rather than
all columns in the primary. I tried using @JoinColumn and specify only
column and it doesnt work. Can you pls point me to the write annotation ?

e.g. A has identity (id,version,type,node) . B has 0 to many relation
ship to A. In the "B_A" join table i just want to refer to A's id with
column name "A_id".
Re: JPA Annotation for Composite Foregin Key [message #91689 is a reply to message #91274] Wed, 25 July 2007 03:59 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Vaibhav,
Did you also try referencedColumnName?
Something like:
@JoinColumns({@JoinColumn(name="myParentFirstName" referencedColumnName="firstName"),
@JoinColumn(name="myParentLastName" referencedColumnName="lastName")})

gr. Martin

Vaibhav Kulkarni wrote:
> Martin
>
> I just verified 2007/07/18 release and it works. Thanks for fixing it.
>
> I have one more question. I have composite primary key with 4 columns
> but in some cases I just want to add id column in the join table rather
> than all columns in the primary. I tried using @JoinColumn and specify
> only column and it doesnt work. Can you pls point me to the write
> annotation ?
>
> e.g. A has identity (id,version,type,node) . B has 0 to many relation
> ship to A. In the "B_A" join table i just want to refer to A's id with
> column name "A_id".
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #92047 is a reply to message #91689] Mon, 30 July 2007 15:14 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I did try using referencedColumnName for both @JoinTable and @JoinColumns
options but it always expects all columns in Primary Key to be included.
Currently i dont find annotation where i can just pick few columns from
Primary Key to represent associations.
Re: JPA Annotation for Composite Foregin Key [message #92062 is a reply to message #92047] Mon, 30 July 2007 20:25 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hmm, this does not seem to work currently.
Is a subset of the pk column-set also unique?

Can you make a (small) test model which reflects what you want to achieve? Then I can try to build
this into a working testcase for Teneo.

gr. Martin

Vaibhav Kulkarni wrote:
> I did try using referencedColumnName for both @JoinTable and
> @JoinColumns options but it always expects all columns in Primary Key to
> be included. Currently i dont find annotation where i can just pick few
> columns from Primary Key to represent associations.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #92209 is a reply to message #92062] Tue, 31 July 2007 15:23 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
In our app, subset of PK will be made unique for certain infrastructure
classes only. All other domain objects will have 4 column PK. As domain
objects will have relation ship to these infrastructure classes , every
domain object will need 4 foreign columns to point to these infrastructure
persistent classes, something i find as redundant information. Hence I am
trying to see if in certain scenarios can I represent relation ship by
choosing only certain columns from PK.

e.g in Parent, Child and Person example I am looking for "parent_child"
table with only 2 columns . parent_firstname and child_firstname (even
though PK is composed of firstname and lastname)

Let me know if I still need to send ecore or testmodel and I will be happy
to do that.
Re: JPA Annotation for Composite Foregin Key [message #92223 is a reply to message #92209] Tue, 31 July 2007 16:25 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Okay I can reuse the person testcase. Can you enter a bugzilla for this? Then I will look at it.

gr. Martin

Vaibhav Kulkarni wrote:
> In our app, subset of PK will be made unique for certain infrastructure
> classes only. All other domain objects will have 4 column PK. As
> domain objects will have relation ship to these infrastructure classes ,
> every domain object will need 4 foreign columns to point to these
> infrastructure persistent classes, something i find as redundant
> information. Hence I am trying to see if in certain scenarios can I
> represent relation ship by choosing only certain columns from PK.
>
> e.g in Parent, Child and Person example I am looking for "parent_child"
> table with only 2 columns . parent_firstname and child_firstname (even
> though PK is composed of firstname and lastname)
>
> Let me know if I still need to send ecore or testmodel and I will be
> happy to do that.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #92267 is a reply to message #92062] Tue, 31 July 2007 21:09 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
Subset of PK will be unique and will be guranteed to have unique values
for some infrastructure classes. All other domain objects will have 4
column PK. As domain objects have relation ship to infrastructure classes
, have 4 column foreign key is redundant and makes data model complex.
Hence i would like to specify 1/2 column as forign key using either
@JoinTable annotation or @JoinColumns annotation.

e.g. in your Parent/Child & Person example , I want only
"parent_firstname" and "child_firstname" columns in "parent_child" join
table.

If there is another mechanism to achive this pls let me know. In EMF
diagram, I just need a way to express association between two entities. In
cetain scenarios full PK makes sense. In few scenario it doesnt.
Re: JPA Annotation for Composite Foregin Key [message #92579 is a reply to message #92223] Fri, 03 August 2007 15:13 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
Martin

Is it possible to provide Secondary key on Entity and use that instead (in
some cases) to represent foreign keys ? If Yes then i dont need to use
subset of PK and i can define secondary key for certain infrastructure
classes.

Your comment is appreciated.
Re: JPA Annotation for Composite Foregin Key [message #92598 is a reply to message #92579] Fri, 03 August 2007 22:25 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I was thinking to try property-ref (see the hibernate manual), to get property-ref working the
refered-to eclass needs a property which is part of a unique index. Is this available in your case?

It will be a few days before I have time to look at this further.

gr. Martin

Vaibhav Kulkarni wrote:
> Martin
>
> Is it possible to provide Secondary key on Entity and use that instead
> (in some cases) to represent foreign keys ? If Yes then i dont need to
> use subset of PK and i can define secondary key for certain
> infrastructure classes.
>
> Your comment is appreciated.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #608699 is a reply to message #89012] Wed, 11 July 2007 16:59 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
What is the exception and how does your annotation look like?
And can you show (part of) the ecore describing this relation?

gr. Martin

Vaibhav Kulkarni wrote:
> I have composite key in Object A i.e. (type,id,version,node). Object B
> has relation ship to A. So when I use Teneo to create HBM file and then
> create DDL script from it , I need those 4 fields be added in table B
> (with convention as A_id,A_type ...etc.) and foreign key is created in
> table B with reference to table A.
>
> I tried that with @JoinColumns annotations and Teneo gave me exception
> sayings is not supported. Whats the mechansim to represent composite
> foregin keys ?
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #608704 is a reply to message #89028] Wed, 11 July 2007 20:57 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I get following exception :

Caused by: org.eclipse.emf.teneo.hibernate.mapper.MappingException:
Unsupported multiple join columns, EReference/subclass
at
org.eclipse.emf.teneo.hibernate.mapper.ManyToOneMapper.proce ss(ManyToOneMapper.java:64)
at
org.eclipse.emf.teneo.hibernate.mapper.FeatureMapper.process PAnnotatedEReference(FeatureMapper.java:161)
at
org.eclipse.emf.teneo.hibernate.mapper.FeatureMapper.process (FeatureMapper.java:97)
at
org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processF eature(EntityMapper.java:553)
at
org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processF eatures(EntityMapper.java:438)
at
org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processE ntity(EntityMapper.java:335)
at
org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.processPAClass(HibernateMappingGenerator.java:194)
at
org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.processPersistentClasses(HibernateMappingGenerator.java :162)
at
org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.generate(HibernateMappingGenerator.java:124)
... 7 more

I am cut pasting annotations in ecore ..

<eClassifiers xsi:type="ecore:EClass" name="RelationshipClass">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="relationname"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="subclass"
eType="#//Subclass">
<eAnnotations source="teneo.jpa">
<details key="appinfo"
value=" @JoinColumns({@JoinColumn(name=&quot;owning_id&quot; ,
referencedColumnName=&quot;id&quot;),@JoinColumn(nam e=&quot;owning_ver&quot;,
referencedColumnName=&quot;version&quot;),@JoinColum n(name=&quot;owning_type&quot;,
referencedColumnName=&quot;type&quot;)})"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>

RelationshipClass has 0 to 1 relationship to class named "Subclass". This
Subclass has its primary key as id, type and version. So I want to add
this 3 columns in RelationshipClass table with customized names (as shown
above) as foreign keys.


is this right annotation to be used to solve composite forign key issue ?
Re: JPA Annotation for Composite Foregin Key [message #608705 is a reply to message #89101] Wed, 11 July 2007 21:11 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Yes, I see, multiple join columns on a many-to-one are not yet supported. I am currently working on
a new release. If you enter a bugzilla for this then I can try to incorporate this in this next
release (within a week).

gr. Martin

Vaibhav Kulkarni wrote:
> I get following exception :
>
> Caused by: org.eclipse.emf.teneo.hibernate.mapper.MappingException:
> Unsupported multiple join columns, EReference/subclass
> at
> org.eclipse.emf.teneo.hibernate.mapper.ManyToOneMapper.proce ss(ManyToOneMapper.java:64)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.FeatureMapper.process PAnnotatedEReference(FeatureMapper.java:161)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.FeatureMapper.process (FeatureMapper.java:97)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processF eature(EntityMapper.java:553)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processF eatures(EntityMapper.java:438)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.EntityMapper.processE ntity(EntityMapper.java:335)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.processPAClass(HibernateMappingGenerator.java:194)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.processPersistentClasses(HibernateMappingGenerator.java :162)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.HibernateMappingGener ator.generate(HibernateMappingGenerator.java:124)
>
> ... 7 more
>
> I am cut pasting annotations in ecore ..
>
> <eClassifiers xsi:type="ecore:EClass" name="RelationshipClass">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="relationname"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="subclass"
> eType="#//Subclass">
> <eAnnotations source="teneo.jpa">
> <details key="appinfo"
> value=" @JoinColumns({@JoinColumn(name=&quot;owning_id&quot; ,
> referencedColumnName=&quot;id&quot;),@JoinColumn(nam e=&quot;owning_ver&quot;,
> referencedColumnName=&quot;version&quot;),@JoinColum n(name=&quot;owning_type&quot;,
> referencedColumnName=&quot;type&quot;)})"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
>
> RelationshipClass has 0 to 1 relationship to class named "Subclass".
> This Subclass has its primary key as id, type and version. So I want to
> add this 3 columns in RelationshipClass table with customized names (as
> shown above) as foreign keys.
>
>
> is this right annotation to be used to solve composite forign key issue ?
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #608706 is a reply to message #89101] Wed, 11 July 2007 21:15 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I have similar issue for composite primary keys when
@Inheritance(strategy="JOINED") is used between concrete parent class and
its concrete sub class. I want only composite parent keys are added in
subclass table as a foreign keys to parent class. Parent table should have
only properties in Parent class and Child table should have only
properties in Child subclass.

I get following exception :

Caused by: org.hibernate.MappingException: Foreign key
(FK6F2A564026128853:relationshipclass [subclass_subclass_id])) must have
same number of columns as the referenced primary key (subclass
[id,type,version])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.jav a:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.jav a:73)
Re: JPA Annotation for Composite Foregin Key [message #608707 is a reply to message #89131] Wed, 11 July 2007 21:57 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080706000602050300090804
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

I have a testcase which covers this case as well as a one-to-many using a composite-key. I have
attached the ecore and the resulting hbm so you can see if there are any differences with your approach.

gr. martin

Vaibhav Kulkarni wrote:
> I have similar issue for composite primary keys when
> @Inheritance(strategy="JOINED") is used between concrete parent class
> and its concrete sub class. I want only composite parent keys are added
> in subclass table as a foreign keys to parent class. Parent table should
> have only properties in Parent class and Child table should have only
> properties in Child subclass.
>
> I get following exception :
>
> Caused by: org.hibernate.MappingException: Foreign key
> (FK6F2A564026128853:relationshipclass [subclass_subclass_id])) must have
> same number of columns as the referenced primary key (subclass
> [id,type,version])
> at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.jav a:90)
> at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.jav a:73)
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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

--------------080706000602050300090804
Content-Type: text/xml;
name="JoinColumnsTest$1_mysql_s_o_hibernate.hbm.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="JoinColumnsTest$1_mysql_s_o_hibernate.hbm.xml"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- Generated by Teneo on Wed Jul 11 23:53:48 CEST 2007 -->
<hibernate-mapping auto-import="false">
<class name=" org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.im pl.PersonImpl " entity-name="Person" abstract="false" lazy="false" table="`person`">
<meta attribute="eclassName">Person</meta>
<meta attribute="epackage"> http://www.eclipse.org/emf/teneo/samples/emf/annotations/joi ncolumns</meta>
<composite-id class=" org.eclipse.emf.teneo.samples.emf.annotations.compositeid.Pe rsonID " mapped="true">
<key-property name="firstName" type="java.lang.String">
<column not-null="true" unique="false" name="`firstname`"/>
</key-property>
<key-property name="lastName" type="java.lang.String">
<column not-null="true" unique="false" name="`lastname`"/>
</key-property>
</composite-id>
<version name="myversion" column="myversion" access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
<meta attribute="syntheticVersion">true</meta>
</version>
</class>
<joined-subclass name=" org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.im pl.ParentImpl " entity-name="Parent" abstract="false" lazy="false" extends="Person" table="`parent`">
<meta attribute="eclassName">Parent</meta>
<meta attribute="epackage"> http://www.eclipse.org/emf/teneo/samples/emf/annotations/joi ncolumns</meta>
<key>
<column name="`person_firstname`"/>
<column name="`person_lastname`"/>
</key>
<list name="children" lazy="true" cascade="merge,persist,save-update,lock,refresh">
<key update="true">
<column name="`myparentfirstname`" not-null="false" unique="false"/>
<column name="`myparentlastname`" not-null="false" unique="false"/>
</key>
<list-index column="`parent_children_idx`"/>
<one-to-many entity-name="Child"/>
</list>
</joined-subclass>
<joined-subclass name=" org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.im pl.ChildImpl " entity-name="Child" abstract="false" lazy="false" extends="Person" table="`child`">
<meta attribute="eclassName">Child</meta>
<meta attribute="epackage"> http://www.eclipse.org/emf/teneo/samples/emf/annotations/joi ncolumns</meta>
<key>
<column name="`person_firstname`"/>
<column name="`person_lastname`"/>
</key>
</joined-subclass>
</hibernate-mapping>
--------------080706000602050300090804
Content-Type: text/xml;
name="jc.ecore"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="jc.ecore"

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="joincolumns"
nsURI=" http://www.eclipse.org/emf/teneo/samples/emf/annotations/joi ncolumns" nsPrefix="joincolumns">
<eClassifiers xsi:type="ecore:EClass" name="Parent" eSuperTypes="#//Person">
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//Child">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value=" @JoinColumns({@JoinColumn(name=&quot;myParentFirstName&a mp;quot; referencedColumnName=&quot;firstName&quot;),&#xA ;&#x9;@JoinColumn(name=&quot;myParentLastName&qu ot; referencedColumnName=&quot;lastName&quot;)})"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Child" eSuperTypes="#//Person"/>
<eClassifiers xsi:type="ecore:EClass" name="Person">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value=" @IdClass(org.eclipse.emf.teneo.samples.emf.annotations.compo siteid.PersonID) "/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="firstName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Id"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="lastName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Id"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>

--------------080706000602050300090804--
Re: JPA Annotation for Composite Foregin Key [message #608736 is a reply to message #89146] Thu, 12 July 2007 21:19 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I have noticed few differences as well as I am confused with the test case
result and DDL it generates.

1) I am using @EmbeddedId and @Embeddeable and test case uses @IdClass.
Hopefullly they should work the same way. It works for me for one class.
But as soon as I extend that class it doesnt.

2) Test ecore shows 0 to many relation ship between Parent and Child. That
means it should create join table 4 columns (parent_firstname,
parent_lastname, child_firstname , child_lastname) .. Its doing some thing
different. Its instead adding these columns into child table . If relation
ships is shown between Parent and Child , then shouldnt it create tables
accordingly ?

3) If Parent has foreign key to Person , then why its adding Persons
primary key to Child table. One can go from Child to Parent and then to
Person to pick up all colums from Parent .

I will try to see if @IdClass works but I do see with representing these
relationships in the data base.
Re: JPA Annotation for Composite Foregin Key [message #608737 is a reply to message #89591] Thu, 12 July 2007 21:27 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000406030309050207020308
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

See my comments inline.

gr. Martin

Vaibhav Kulkarni wrote:
> I have noticed few differences as well as I am confused with the test
> case result and DDL it generates.
>
> 1) I am using @EmbeddedId and @Embeddeable and test case uses @IdClass.
> Hopefullly they should work the same way. It works for me for one class.
> But as soon as I extend that class it doesnt.
MT>> I attached also a testcase which has embeddedid. Unfortunately it is simpler
than the joincolumn one.

>
> 2) Test ecore shows 0 to many relation ship between Parent and Child.
> That means it should create join table 4 columns (parent_firstname,
> parent_lastname, child_firstname , child_lastname) .. Its doing some
> thing different. Its instead adding these columns into child table . If
> relation ships is shown between Parent and Child , then shouldnt it
> create tables accordingly ?
MT>> It is a relation without a join table, so then the foreign key is placed
in the child table.
With a join table it would look differently but I did not test that case.

>
> 3) If Parent has foreign key to Person , then why its adding Persons
> primary key to Child table. One can go from Child to Parent and then to
> Person to pick up all colums from Parent .
MT>> Also child inherits from Person, therefore there is a foreign key from the child table
to the person table.

>
> I will try to see if @IdClass works but I do see with representing these
> relationships in the data base.
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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

--------------000406030309050207020308
Content-Type: text/xml;
name="embeddedid.ecore"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="embeddedid.ecore"

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="embeddedid"
nsURI=" http://www.eclipse.org/emf/teneo/samples/emf/annotations/emb eddedid" nsPrefix="embeddedid">
<eClassifiers xsi:type="ecore:EClass" name="Name">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Embeddable"/>
</eAnnotations>
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="Name"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="firstName" unique="false"
lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="firstName"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="lastName" unique="false"
lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="lastName"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Person">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="Person"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="name" lowerBound="1" eType="#//Name"
containment="true" resolveProxies="false">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@EmbeddedId"/>
</eAnnotations>
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="name"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="address" unique="false"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@Lob"/>
</eAnnotations>
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="address"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>

--------------000406030309050207020308
Content-Type: text/xml;
name="EmbeddedId.xsd"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="EmbeddedId.xsd"

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace=" http://www.eclipse.org/emf/teneo/samples/emf/annotations/emb eddedid"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:this=" http://www.eclipse.org/emf/teneo/samples/emf/annotations/emb eddedid">

<xsd:complexType name="Person">
<xsd:sequence>
<xsd:element name="name" type="this:Name">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@EmbeddedId</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="address" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Lob</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Name">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Embeddable</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="firstName" type="xsd:string"/>
<xsd:element name="lastName" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>

</xsd:schema>
--------------000406030309050207020308
Content-Type: text/xml;
name="EmbeddedIdAction_mysql_s_o_hibernate.hbm.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="EmbeddedIdAction_mysql_s_o_hibernate.hbm.xml"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- Generated by Teneo on Thu Jul 12 19:26:02 CEST 2007 -->
<hibernate-mapping auto-import="false">
<class name=" org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.imp l.PersonImpl " entity-name="Person" abstract="false" lazy="false" table="`person`">
<meta attribute="eclassName">Person</meta>
<meta attribute="epackage"> http://www.eclipse.org/emf/teneo/samples/emf/annotations/emb eddedid</meta>
<composite-id name="name" class=" org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.imp l.NameImpl ">
<key-property name="firstName" type="java.lang.String">
<column not-null="true" unique="false" name="`firstname`"/>
</key-property>
<key-property name="lastName" type="java.lang.String">
<column not-null="true" unique="false" name="`lastname`"/>
</key-property>
</composite-id>
<version name="e_version" column="e_version" access=" org.eclipse.emf.teneo.hibernate.mapping.property.VersionProp ertyHandler ">
<meta attribute="syntheticVersion">true</meta>
</version>
<property name="address" lazy="false" insert="true" update="true" not-null="false" unique="false" type="text">
<column not-null="false" unique="false" name="`address`"/>
</property>
</class>
</hibernate-mapping>
--------------000406030309050207020308--
Re: JPA Annotation for Composite Foregin Key [message #608759 is a reply to message #89605] Tue, 17 July 2007 10:15 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I have summarized issues after doing some more evaluation around JPA
annotations.

1) Join table is not created for many to many or many to one non contained
associations even though Teneo persistence option of
"JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS=true" WHEN primary key is
composed of more than one columns. When I changed Primary Key to contain
only one column , it worked well & I did not had to specify @JoinTable
annotations. As I beleive this option is created to avoid specifying
explicit @JoinTable annotation. Pls fix this and test it using composite
primary key expresedd using @IdClass or @Embedeable/@EmbeddedId

2) If JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS option is set to "true"
and @JoinColumns annotations is used then it does create DDL and adds
foreign key columns in the table for class representing other side of the
relation ship . I think this is covered in your Person/Child/Parent test
case where columns are added in Child table even though "children"
relationship is present in Parent class. This works with both single
column PK as well as composite PK. But does than mean @JoinColumns
annotations take precedence over JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS
?

3) Same thing true for INHERITANCE_MAPPING=JOINED settings. It works for
single column PK but not for composite PK. Once composite PK is defined it
fails to add one column in the table (representing subclass) for every
column in PK of parent class. Once fixed it also needs to be tested with
JPA annotation of
@Inheritance(strategy="JOINED") to check if it gives same result as
INHERITANCE_MAPPING=JOINED settings.

4) Came across below exception when attempt was made to customize inverse
column names using @JoinTable annotation.

Caused by: org.xml.sax.SAXParseException: Attribute "update" must be
declared for element type "many-to-many".
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. createSAXParseException(Unknown
Source)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. error(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(Unknown
Source)

Heres is annotation :

"appinfo", "@JoinTable(name=\"parent_child\",
joinColumns=@JoinColumn(name=\"parent_FirstName\"
referencedColumnName=\"firstName\"), " +
"inverseJoinColumns=@JoinColumn(name=\"child_FirstName\"
referencedColumnName=\"firstName\") )"
Re: JPA Annotation for Composite Foregin Key [message #608772 is a reply to message #89967] Tue, 17 July 2007 15:25 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Vaibhav,
See my comments in line.

Vaibhav Kulkarni wrote:
> I have summarized issues after doing some more evaluation around JPA
> annotations.
>
> 1) Join table is not created for many to many or many to one non
> contained associations even though Teneo persistence option of
> "JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS=true" WHEN primary key is
> composed of more than one columns. When I changed Primary Key to contain
> only one column , it worked well & I did not had to specify @JoinTable
> annotations. As I beleive this option is created to avoid specifying
> explicit @JoinTable annotation. Pls fix this and test it using composite
> primary key expresedd using @IdClass or @Embedeable/@EmbeddedId
MT>> Yes I am looking into this.

Btw, to me (as a non-native english speaker) the phrase 'Pls fix this and test it' sounds kind of
commandeering, probably you don't mean it that way...

>
> 2) If JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS option is set to "true"
> and @JoinColumns annotations is used then it does create DDL and adds
> foreign key columns in the table for class representing other side of
> the relation ship . I think this is covered in your Person/Child/Parent
> test case where columns are added in Child table even though "children"
> relationship is present in Parent class. This works with both single
> column PK as well as composite PK. But does than mean @JoinColumns
> annotations take precedence over
> JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS ?
MT>> No the option should take precedence, if it doesn't then it is a bug. As I am looking into this
topic (of composite-ids) right now I will also check it.

> 3) Same thing true for INHERITANCE_MAPPING=JOINED settings. It works
> for single column PK but not for composite PK. Once composite PK is
> defined it fails to add one column in the table (representing subclass)
> for every column in PK of parent class. Once fixed it also needs to be
> tested with JPA annotation of @Inheritance(strategy="JOINED") to check
> if it gives same result as INHERITANCE_MAPPING=JOINED settings.
MT> The person-child testcase I sent you earlier covers this case, all test cases are run for single
and joined inheritance mapping.

>
> 4) Came across below exception when attempt was made to customize
> inverse column names using @JoinTable annotation.
MT>> I will adapt the testcase to also include a jointable with a composite-id, hopefully this
exception will also appear there.

>
> Caused by: org.xml.sax.SAXParseException: Attribute "update" must be
> declared for element type "many-to-many".
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. createSAXParseException(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. error(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(Unknown
> Source)
>
> Heres is annotation :
>
> "appinfo", "@JoinTable(name=\"parent_child\",
> joinColumns=@JoinColumn(name=\"parent_FirstName\"
> referencedColumnName=\"firstName\"), " +
>
> "inverseJoinColumns=@JoinColumn(name=\"child_FirstName\"
> referencedColumnName=\"firstName\") )"
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #608778 is a reply to message #90168] Wed, 18 July 2007 00:25 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
Martin

Thanks and I apologize if you interpret it that way. Ofcourse i didnt mean
it that way.

Thanks again and you being a great help.
Re: JPA Annotation for Composite Foregin Key [message #608788 is a reply to message #90260] Wed, 18 July 2007 11:23 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Vaibhav,
Thanks, no problem, regarding the four topics you mention:
1) the testcase I added yesterday to your bugzilla covers this case, this works now afaics.
2) I tested this case but I could not replicate this issue
3) the testcase covers this also and it seemed to work.
4) I was able to reproduce this error, it has been solved in cvs.

Let me know if the testcase I added to the bugzilla covers your case (or not ofcourse).

This will be in the next build (today or tomorrow).

gr. Martin

Vaibhav Kulkarni wrote:
> Martin
> Thanks and I apologize if you interpret it that way. Ofcourse i didnt
> mean it that way.
> Thanks again and you being a great help.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #608845 is a reply to message #90409] Mon, 23 July 2007 09:55 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
Martin

I just verified 2007/07/18 release and it works. Thanks for fixing it.

I have one more question. I have composite primary key with 4 columns but
in some cases I just want to add id column in the join table rather than
all columns in the primary. I tried using @JoinColumn and specify only
column and it doesnt work. Can you pls point me to the write annotation ?

e.g. A has identity (id,version,type,node) . B has 0 to many relation
ship to A. In the "B_A" join table i just want to refer to A's id with
column name "A_id".
Re: JPA Annotation for Composite Foregin Key [message #608891 is a reply to message #91274] Wed, 25 July 2007 03:59 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Vaibhav,
Did you also try referencedColumnName?
Something like:
@JoinColumns({@JoinColumn(name="myParentFirstName" referencedColumnName="firstName"),
@JoinColumn(name="myParentLastName" referencedColumnName="lastName")})

gr. Martin

Vaibhav Kulkarni wrote:
> Martin
>
> I just verified 2007/07/18 release and it works. Thanks for fixing it.
>
> I have one more question. I have composite primary key with 4 columns
> but in some cases I just want to add id column in the join table rather
> than all columns in the primary. I tried using @JoinColumn and specify
> only column and it doesnt work. Can you pls point me to the write
> annotation ?
>
> e.g. A has identity (id,version,type,node) . B has 0 to many relation
> ship to A. In the "B_A" join table i just want to refer to A's id with
> column name "A_id".
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #609357 is a reply to message #91689] Mon, 30 July 2007 15:14 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
I did try using referencedColumnName for both @JoinTable and @JoinColumns
options but it always expects all columns in Primary Key to be included.
Currently i dont find annotation where i can just pick few columns from
Primary Key to represent associations.
Re: JPA Annotation for Composite Foregin Key [message #609361 is a reply to message #92047] Mon, 30 July 2007 20:25 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hmm, this does not seem to work currently.
Is a subset of the pk column-set also unique?

Can you make a (small) test model which reflects what you want to achieve? Then I can try to build
this into a working testcase for Teneo.

gr. Martin

Vaibhav Kulkarni wrote:
> I did try using referencedColumnName for both @JoinTable and
> @JoinColumns options but it always expects all columns in Primary Key to
> be included. Currently i dont find annotation where i can just pick few
> columns from Primary Key to represent associations.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #609394 is a reply to message #92062] Tue, 31 July 2007 15:23 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
In our app, subset of PK will be made unique for certain infrastructure
classes only. All other domain objects will have 4 column PK. As domain
objects will have relation ship to these infrastructure classes , every
domain object will need 4 foreign columns to point to these infrastructure
persistent classes, something i find as redundant information. Hence I am
trying to see if in certain scenarios can I represent relation ship by
choosing only certain columns from PK.

e.g in Parent, Child and Person example I am looking for "parent_child"
table with only 2 columns . parent_firstname and child_firstname (even
though PK is composed of firstname and lastname)

Let me know if I still need to send ecore or testmodel and I will be happy
to do that.
Re: JPA Annotation for Composite Foregin Key [message #609396 is a reply to message #92209] Tue, 31 July 2007 16:25 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Okay I can reuse the person testcase. Can you enter a bugzilla for this? Then I will look at it.

gr. Martin

Vaibhav Kulkarni wrote:
> In our app, subset of PK will be made unique for certain infrastructure
> classes only. All other domain objects will have 4 column PK. As
> domain objects will have relation ship to these infrastructure classes ,
> every domain object will need 4 foreign columns to point to these
> infrastructure persistent classes, something i find as redundant
> information. Hence I am trying to see if in certain scenarios can I
> represent relation ship by choosing only certain columns from PK.
>
> e.g in Parent, Child and Person example I am looking for "parent_child"
> table with only 2 columns . parent_firstname and child_firstname (even
> though PK is composed of firstname and lastname)
>
> Let me know if I still need to send ecore or testmodel and I will be
> happy to do that.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: JPA Annotation for Composite Foregin Key [message #609401 is a reply to message #92062] Tue, 31 July 2007 21:09 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
Subset of PK will be unique and will be guranteed to have unique values
for some infrastructure classes. All other domain objects will have 4
column PK. As domain objects have relation ship to infrastructure classes
, have 4 column foreign key is redundant and makes data model complex.
Hence i would like to specify 1/2 column as forign key using either
@JoinTable annotation or @JoinColumns annotation.

e.g. in your Parent/Child & Person example , I want only
"parent_firstname" and "child_firstname" columns in "parent_child" join
table.

If there is another mechanism to achive this pls let me know. In EMF
diagram, I just need a way to express association between two entities. In
cetain scenarios full PK makes sense. In few scenario it doesnt.
Re: JPA Annotation for Composite Foregin Key [message #609423 is a reply to message #92223] Fri, 03 August 2007 15:13 Go to previous message
No real name is currently offline No real nameFriend
Messages: 36
Registered: July 2009
Member
Martin

Is it possible to provide Secondary key on Entity and use that instead (in
some cases) to represent foreign keys ? If Yes then i dont need to use
subset of PK and i can define secondary key for certain infrastructure
classes.

Your comment is appreciated.
Re: JPA Annotation for Composite Foregin Key [message #609424 is a reply to message #92579] Fri, 03 August 2007 22:25 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I was thinking to try property-ref (see the hibernate manual), to get property-ref working the
refered-to eclass needs a property which is part of a unique index. Is this available in your case?

It will be a few days before I have time to look at this further.

gr. Martin

Vaibhav Kulkarni wrote:
> Martin
>
> Is it possible to provide Secondary key on Entity and use that instead
> (in some cases) to represent foreign keys ? If Yes then i dont need to
> use subset of PK and i can define secondary key for certain
> infrastructure classes.
>
> Your comment is appreciated.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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:[EMF Transaction] ConcurrentModificationException while unloading a resource
Next Topic:[Teneo] Model persistence performance
Goto Forum:
  


Current Time: Fri Mar 29 13:44:25 GMT 2024

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

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

Back to the top