Home » Modeling » EMF » [Teneo] One-To-One Mappings Ignoring Column Names(Column Name annotation not reflected in Hibernate Mapping)
[Teneo] One-To-One Mappings Ignoring Column Names [message #1002419] |
Fri, 18 January 2013 14:43 |
Rob Mising name Messages: 118 Registered: July 2010 |
Senior Member |
|
|
Hi Martin,
I am seeing some strange behaviour and would be grateful if you could spare a minute to assist me. If I have a one-to-one mapping as follows
<eClassifiers xsi:type="ecore:EClass" name="Case1">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="Case1"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eAnnotations source="bds">
<details key="isCase" value="true"/>
</eAnnotations>
<eAnnotations source="teneo.jpa">
<details key="value" value="@Table(name="MYTEST_CASE1")
@DiscriminatorValue("com.example.mytest.Case1")"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="two" lowerBound="1" eType="//Case2" eOpposite="//Case2/one">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="two"/>
</eAnnotations>
<eAnnotations source="teneo.jpa">
<details key="value" value="@Column(name="TWO")
@ForeignKey(name="CASE1_TWO")"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId">
<eAnnotations source="teneo.jpa">
<details key="value" value="@Id
@Column(name="BDS_ID", nullable="false")"/>
</eAnnotations>
<eAnnotations source="bds">
<details key="isId" value="true"/>
</eAnnotations>
<eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//ELongObject"/>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsVersion">
<eAnnotations source="teneo.jpa">
<details key="value" value="@Column(name="BDS_VERSION")
@Version"/>
</eAnnotations>
<eAnnotations source="bds">
<details key="isVersion" value="true"/>
</eAnnotations>
<eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//ELongObject"/>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Case2">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="Case2"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eAnnotations source="bds">
<details key="isCase" value="true"/>
</eAnnotations>
<eAnnotations source="teneo.jpa">
<details key="value" value="@Table(name="MYTEST_CASE2")
@DiscriminatorValue("com.example.mytest.Case2")"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="one" lowerBound="1" eType="//Case1" eOpposite="//Case1/two">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="one"/>
</eAnnotations>
<eAnnotations source="teneo.jpa">
<details key="value" value="@Column(name="ONE")
@ForeignKey(name="CASE2_ONE")"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId">
<eAnnotations source="teneo.jpa">
<details key="value" value="@Id
@Column(name="BDS_ID", nullable="false")"/>
</eAnnotations>
<eAnnotations source="bds">
<details key="isId" value="true"/>
</eAnnotations>
<eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//ELongObject"/>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsVersion">
<eAnnotations source="teneo.jpa">
<details key="value" value="@Column(name="BDS_VERSION")
@Version"/>
</eAnnotations>
<eAnnotations source="bds">
<details key="isVersion" value="true"/>
</eAnnotations>
<eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//ELongObject"/>
</eStructuralFeatures>
</eClassifiers>
Where I have specified that the column names should be set values (in this example just in capitals). Then it does not seem to be used when creating the hibernate mapping.
<hibernate-mapping auto-import="false">
<class entity-name="mytest.Case1" abstract="false" lazy="false" discriminator-value="com.example.mytest.Case1" table="`BDS_1_ROB_CASE1`">
<meta attribute="eclassName">Case1</meta>
<meta attribute="epackage">http://example.com/mytest</meta>
<id name="bdsId" type="java.lang.Long">
<column not-null="true" unique="false" name="`BDS_ID`"/>
<generator class="com.naming.CaseDataStoreIdGenerator"/>
</id>
<discriminator column="`DTYPE`" type="string"/>
<version name="bdsVersion" type="java.lang.Long">
<column not-null="false" unique="false" name="`BDS_VERSION`"/>
</version>
<one-to-one name="two" entity-name="mytest.Case2" foreign-key="FK_1_ROB_TWO" cascade="merge,persist,save-update,lock,refresh" lazy="false" property-ref="one" constrained="true"/>
</class>
<class entity-name="mytest.Case2" abstract="false" lazy="false" discriminator-value="com.example.mytest.Case2" table="`BDS_1_ROB_CASE2`">
<meta attribute="eclassName">Case2</meta>
<meta attribute="epackage">http://example.com/mytest</meta>
<id name="bdsId" type="java.lang.Long">
<column not-null="true" unique="false" name="`BDS_ID`"/>
<generator class="com.naming.CaseDataStoreIdGenerator"/>
</id>
<discriminator column="`DTYPE`" type="string"/>
<version name="bdsVersion" type="java.lang.Long">
<column not-null="false" unique="false" name="`BDS_VERSION`"/>
</version>
<many-to-one name="one" entity-name="mytest.Case1" cascade="merge,persist,save-update,lock,refresh" not-null="true" lazy="false" foreign-key="FK_1_ROB_ONE" insert="true" update="true" unique="true"/>
</class>
</hibernate-mapping>
Which in turn results in the DB script:
create table [BDS_1_ROB_CASE1] ([BDS_ID] numeric(19,0) not null, [DTYPE] nvarchar(255) not null, [BDS_VERSION] numeric(19,0) null, primary key ([BDS_ID]))
create table [BDS_1_ROB_CASE2] ([BDS_ID] numeric(19,0) not null, [DTYPE] nvarchar(255) not null, [BDS_VERSION] numeric(19,0) null, one numeric(19,0) not null unique, primary key ([BDS_ID]))
alter table [BDS_1_ROB_CASE2] add constraint FK_1_ROB_ONE foreign key (one) references [BDS_1_ROB_CASE1]
Note the column name "one" instead of "ONE"
I think if the name on the hibernate mapping was changed to have a column="`ONE`" then it would generate the DB mapping as expected.
<many-to-one name="one" column="`ONE`" entity-name="mytest.Case1" cascade="merge,persist,save-update,lock,refresh" not-null="true" lazy="false" foreign-key="FK_1_ROB_ONE" insert="true" update="true" unique="true"/>
I have also had a look to see if there is a way to override this value be picking up the name using the SQLNameStrategy - but I didn't have any luck
If you are able to make any suggestions I would be very grateful.
Thanks
Rob
[Updated on: Tue, 22 January 2013 11:46] Report message to a moderator
|
|
|
Re: [Teneo] One-To-One Mappings Ignoring Column Names [message #1002451 is a reply to message #1002419] |
Fri, 18 January 2013 15:57 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Rob,
For EReferences you need to use JoinColumn instead of Column. Also these options influence the casing:
teneo.naming.auto_adapt_manual_set_sql_names
teneo.naming.strategy
See here:
http://wiki.eclipse.org/Teneo/Hibernate/Configuration_Options
gr. Martin
On 01/18/2013 03:43 PM, Rob Mising name wrote:
> Hi Martin,
>
> I am seeing some strange behaviour and would be grateful if you could spare a minute to assist me. If I have a
> one-to-one mapping as follows
>
> <eClassifiers xsi:type="ecore:EClass" name="Case1">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Case1"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isCase" value="true"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Table(name="MYTEST_CASE1")
> @DiscriminatorValue("com.example.mytest.Case1")"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EReference" name="two" lowerBound="1" eType="//Case2" eOpposite="//Case2/one">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="two"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Column(name="TWO")
> @ForeignKey(name="CASE1_TWO")"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Id
> @Column(name="BDS_ID", nullable="false")"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isId" value="true"/>
> </eAnnotations>
> <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//ELongObject"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsVersion">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Column(name="BDS_VERSION")
> @Version"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isVersion" value="true"/>
> </eAnnotations>
> <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//ELongObject"/>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Case2">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Case2"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isCase" value="true"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Table(name="MYTEST_CASE2")
> @DiscriminatorValue("com.example.mytest.Case2")"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EReference" name="one" lowerBound="1" eType="//Case1" eOpposite="//Case1/two">
> <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="one"/>
> </eAnnotations>
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Column(name="ONE")
> @ForeignKey(name="CASE2_ONE")"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Id
> @Column(name="BDS_ID", nullable="false")"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isId" value="true"/>
> </eAnnotations>
> <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//ELongObject"/>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsVersion">
> <eAnnotations source="teneo.jpa">
> <details key="value" value="@Column(name="BDS_VERSION")
> @Version"/>
> </eAnnotations>
> <eAnnotations source="bds">
> <details key="isVersion" value="true"/>
> </eAnnotations>
> <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//ELongObject"/>
> </eStructuralFeatures>
> </eClassifiers>
>
>
> Where I have specified that the column names should be set values (in this example just in capitals). Then it does not
> seem to be used when creating the hibernate mapping.
>
> <hibernate-mapping auto-import="false">
> <class entity-name="mytest.Case1" abstract="false" lazy="false" discriminator-value="com.example.mytest.Case1"
> table="`BDS_1_ROB_CASE1`">
> <meta attribute="eclassName">Case1</meta>
> <meta attribute="epackage">http://example.com/mytest</meta>
> <id name="bdsId" type="java.lang.Long">
> <column not-null="true" unique="false" name="`BDS_ID`"/>
> <generator class="com.tibco.bds.core.naming.CaseDataStoreIdGenerator"/>
> </id>
> <discriminator column="`DTYPE`" type="string"/>
> <version name="bdsVersion" type="java.lang.Long">
> <column not-null="false" unique="false" name="`BDS_VERSION`"/>
> </version>
> <one-to-one name="two" entity-name="mytest.Case2" foreign-key="FK_1_ROB_TWO"
> cascade="merge,persist,save-update,lock,refresh" lazy="false" property-ref="one" constrained="true"/>
> </class>
> <class entity-name="mytest.Case2" abstract="false" lazy="false" discriminator-value="com.example.mytest.Case2"
> table="`BDS_1_ROB_CASE2`">
> <meta attribute="eclassName">Case2</meta>
> <meta attribute="epackage">http://example.com/mytest</meta>
> <id name="bdsId" type="java.lang.Long">
> <column not-null="true" unique="false" name="`BDS_ID`"/>
> <generator class="com.tibco.bds.core.naming.CaseDataStoreIdGenerator"/>
> </id>
> <discriminator column="`DTYPE`" type="string"/>
> <version name="bdsVersion" type="java.lang.Long">
> <column not-null="false" unique="false" name="`BDS_VERSION`"/>
> </version>
> <many-to-one name="one" entity-name="mytest.Case1" cascade="merge,persist,save-update,lock,refresh"
> not-null="true" lazy="false" foreign-key="FK_1_ROB_ONE" insert="true" update="true" unique="true"/>
> </class>
> </hibernate-mapping>
>
>
> Which in turn results in the DB script:
>
> create table [BDS_1_ROB_CASE1] ([BDS_ID] numeric(19,0) not null, [DTYPE] nvarchar(255) not null, [BDS_VERSION]
> numeric(19,0) null, primary key ([BDS_ID]))
> create table [BDS_1_ROB_CASE2] ([BDS_ID] numeric(19,0) not null, [DTYPE] nvarchar(255) not null, [BDS_VERSION]
> numeric(19,0) null, one numeric(19,0) not null unique, primary key ([BDS_ID]))
> alter table [BDS_1_ROB_CASE2] add constraint FK_1_ROB_ONE foreign key (one) references [BDS_1_ROB_CASE1]
>
>
> Note the column name "one" instead of "ONE"
>
> I think if the name on the hibernate mapping was changed to have a column="`ONE`" then it would generate the DB mapping
> as expected.
>
> <many-to-one name="one" column="`ONE`" entity-name="mytest.Case1" cascade="merge,persist,save-update,lock,refresh"
> not-null="true" lazy="false" foreign-key="FK_1_ROB_ONE" insert="true" update="true" unique="true"/>
>
> I have also had a look to see if there is a way to override this value be picking up the name using the SQLNameStrategy
> - but I didn't have any luck
>
> If you are able to make any suggestions I would be very grateful.
>
> Thanks
>
> Rob
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
| | | |
Goto Forum:
Current Time: Thu Sep 26 09:21:39 GMT 2024
Powered by FUDForum. Page generated in 0.04236 seconds
|