Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Rob Mising name is currently offline Rob Mising nameFriend
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=&quot;MYTEST_CASE1&quot;)&#xA;@DiscriminatorValue(&quot;com.example.mytest.Case1&quot;)"/>
    </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=&quot;TWO&quot;)&#xA;@ForeignKey(name=&quot;CASE1_TWO&quot;)"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId">
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@Id&#xA;@Column(name=&quot;BDS_ID&quot;, nullable=&quot;false&quot;)"/>
      </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=&quot;BDS_VERSION&quot;)&#xA;@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=&quot;MYTEST_CASE2&quot;)&#xA;@DiscriminatorValue(&quot;com.example.mytest.Case2&quot;)"/>
    </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=&quot;ONE&quot;)&#xA;@ForeignKey(name=&quot;CASE2_ONE&quot;)"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="bdsId">
      <eAnnotations source="teneo.jpa">
        <details key="value" value="@Id&#xA;@Column(name=&quot;BDS_ID&quot;, nullable=&quot;false&quot;)"/>
      </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=&quot;BDS_VERSION&quot;)&#xA;@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 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
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
Re: [Teneo] One-To-One Mappings Ignoring Column Names [message #1002469 is a reply to message #1002451] Fri, 18 January 2013 16:38 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Thanks Martin,

Yes adding the @JoinColumn(name="ONE") did enable it to pick up the name.

As an aside - is there a method I can extend within SQLNameStrategy that would enable me to set things like this - or is it just the annotaion for fields like this?

Thanks

Rob
Re: [Teneo] One-To-One Mappings Ignoring Column Names [message #1002593 is a reply to message #1002469] Fri, 18 January 2013 22:44 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rob,
Probably overriding getColumnName would do the trick.

gr. Martin

On 01/18/2013 05:38 PM, Rob Mising name wrote:
> Thanks Martin,
>
> Yes adding the @JoinColumn(name="ONE") did enable it to pick up the name.
>
> As an aside - is there a method I can extend within SQLNameStrategy that would enable me to set things like this - or is
> it just the annotaion for fields like this?
>
> 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
Re: [Teneo] One-To-One Mappings Ignoring Column Names [message #1003452 is a reply to message #1002593] Mon, 21 January 2013 09:20 Go to previous message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

Thanks for the quick reply again - unfortunately getColumnName does not seem to get called when it is looking for the JoinColumn in this case.

Not to worry, I'll see what I can do with the @JoinColumn annotation.

Thanks for your help

Rob




Martin taal wrote on Fri, 18 January 2013 22:44
Hi Rob,
Probably overriding getColumnName would do the trick.

gr. Martin

Previous Topic:[CDO][EMF Command] problems with SetCommand.redo from empty List
Next Topic:[GWT] Server-side XMLResource
Goto Forum:
  


Current Time: Thu Mar 28 13:35:39 GMT 2024

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

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

Back to the top