Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] DB Keywords not always escapes
[Teneo] DB Keywords not always escapes [message #1121208] Mon, 30 September 2013 11:35 Go to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

I have stumbled accross an issue that I would like your opinion on. It is a case where a DB key word is used in an EReference as the name. (I have attached an eCore that shows this). In my example I use the keyword "order" as the name that will clash.

I have spent some time debugging into the code and spotted that in most cases when the name is set while generating the hibernate mapping file it will call "MappingContext.trunc()" on the name which at the end of the method has:

return this.escapeCharacter + getSqlNameStrategy().convert(useName, false) + 
      this.escapeCharacter;


However in the class AbstractAssociationMapper, the methods addManyToOne and addOneToOne only seem to do:

      element = getHbmContext().getCurrent().addElement("one-to-one")
        .addAttribute("name", assocName).addAttribute(
        "entity-name", targetEntity);


When maybe it should do

      element = getHbmContext().getCurrent().addElement("one-to-one")
        .addAttribute("name", getHbmContext().trunc(assocName)).addAttribute(
        "entity-name", targetEntity);


And also in "OneToOneMapper.createOneToOne()" it has:

associationElement.addAttribute("property-ref", getHbmContext().getPropertyName(otherSide));


When maybe it should do

associationElement.addAttribute("property-ref", getHbmContext().trunc(getHbmContext().getPropertyName(otherSide)));


Does this sound OK to you?

Thanks

Rob
Re: [Teneo] DB Keywords not always escapes [message #1121226 is a reply to message #1121208] Mon, 30 September 2013 11:52 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rob,
The attributes you propose to trunc/escape are placed in the HBM file as hibernate properties, so for the hibernate
metadata itself. They do not directly describe the database schema. So I think your proposal won't work. I would expect
the manytoone to have a join column tag with an escaped name in it.

When does this lead to a problem, what exception do you see in what case?

gr. Martin

On 09/30/2013 01:35 PM, Rob Mising name wrote:
> Hi Martin,
>
> I have stumbled accross an issue that I would like your opinion on. It is a case where a DB key word is used in an EReference as the name. (I have attached an eCore that shows this). In my example I use the keyword "order" as the name that will clash.
>
> I have spent some time debugging into the code and spotted that in most cases when the name is set while generating the hibernate mapping file it will call "MappingContext.trunc()" on the name which at the end of the method has:
>
> return this.escapeCharacter + getSqlNameStrategy().convert(useName, false) +
> this.escapeCharacter;
>
>
> However in the class AbstractAssociationMapper, the methods addManyToOne and addOneToOne only seem to do:
>
> element = getHbmContext().getCurrent().addElement("one-to-one")
> .addAttribute("name", assocName).addAttribute(
> "entity-name", targetEntity);
>
>
> When maybe it should do
>
> element = getHbmContext().getCurrent().addElement("one-to-one")
> .addAttribute("name", getHbmContext().trunc(assocName)).addAttribute(
> "entity-name", targetEntity);
>
>
> And also in "OneToOneMapper.createOneToOne()" it has:
>
> associationElement.addAttribute("property-ref", getHbmContext().getPropertyName(otherSide));
>
>
> When maybe it should do
>
> associationElement.addAttribute("property-ref", getHbmContext().trunc(getHbmContext().getPropertyName(otherSide)));
>
>
> Does this sound OK to you?
>
> 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] DB Keywords not always escapes [message #1121265 is a reply to message #1121208] Mon, 30 September 2013 12:45 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

Thanks for the fast reply. Without the changes detailed the attached eCore wil generate the following hibernate output:

<hibernate-mapping auto-import="false">
	<class entity-name="BasicProduct" abstract="false" lazy="false" discriminator-value="com.example.umlrelationships.BasicProduct" table="`BDS_1_UMLRELTNSHPS_BASICPRODCT`">
		<meta attribute="eclassName">BasicProduct</meta>
		<meta attribute="epackage">http://example.com/umlrelationships</meta>
		<id name="bdsId" type="java.lang.Long">
			<column not-null="true" unique="false" name="`BDS_ID`"/>
			<generator class="com.tibco.bds.core.ecore.IdGenerator"/>
		</id>
		<discriminator column="`DTYPE`" type="string"/>
		<version name="bdsVersion" type="java.lang.Long">
			<column not-null="false" unique="false" name="`BDS_VERSION`"/>
		</version>
		<property name="caseIdentifier1" lazy="false" insert="true" update="true" not-null="true" unique="true" type="java.lang.String" index="IDX_1_UMLRELTNSHPS_73F4C160892">
			<column not-null="true" unique="true" name="`CASEIDENTIFIER1`" length="400" index="IDX_1_UMLRELTNSHPS_73F4C160892"/>
		</property>
	</class>
	<class entity-name="Order" abstract="false" lazy="false" discriminator-value="com.example.umlrelationships.Order" table="`BDS_1_UMLRELTNSHPS_ORDER`">
		<meta attribute="eclassName">Order</meta>
		<meta attribute="epackage">http://example.com/umlrelationships</meta>
		<id name="bdsId" type="java.lang.Long">
			<column not-null="true" unique="false" name="`BDS_ID`"/>
			<generator class="com.tibco.bds.core.ecore.IdGenerator"/>
		</id>
		<discriminator column="`DTYPE`" type="string"/>
		<version name="bdsVersion" type="java.lang.Long">
			<column not-null="false" unique="false" name="`BDS_VERSION`"/>
		</version>
		<property name="caseIdentifier1" lazy="false" insert="true" update="true" not-null="true" unique="true" type="java.lang.String" index="IDX_1_UMLRELTNSHPS_0812BB55C24">
			<column not-null="true" unique="true" name="`CASEIDENTIFIER1`" length="400" index="IDX_1_UMLRELTNSHPS_0812BB55C24"/>
		</property>
		<one-to-one name="product" entity-name="Product" cascade="merge,persist,save-update,lock,refresh" lazy="false" property-ref="order"/>
	</class>
	<subclass entity-name="Product" abstract="false" lazy="false" extends="BasicProduct" discriminator-value="com.example.umlrelationships.Product">
		<meta attribute="eclassName">Product</meta>
		<meta attribute="epackage">http://example.com/umlrelationships</meta>
		<many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false" lazy="false" insert="true" update="true"/>
	</subclass>
</hibernate-mapping>


Which in turn will produce the following SQL:

create table [BDS_1_UMLRELTNSHPS_BASICPRODCT] ([BDS_ID] numeric(19,0) not null, [DTYPE] nvarchar(255) not null, [BDS_VERSION] numeric(19,0) null, [CASEIDENTIFIER1] nvarchar(400) not null unique, order numeric(19,0) null, primary key ([BDS_ID]));
create table [BDS_1_UMLRELTNSHPS_ORDER] ([BDS_ID] numeric(19,0) not null, [DTYPE] nvarchar(255) not null, [BDS_VERSION] numeric(19,0) null, [CASEIDENTIFIER1] nvarchar(400) not null unique, primary key ([BDS_ID]));
create index IDX_1_UMLRELTNSHPS_73F4C160892 on [BDS_1_UMLRELTNSHPS_BASICPRODCT] ([CASEIDENTIFIER1]);
alter table [BDS_1_UMLRELTNSHPS_BASICPRODCT] add constraint FK1B38D06AAE01E7C foreign key (order) references [BDS_1_UMLRELTNSHPS_ORDER];
create index IDX_1_UMLRELTNSHPS_0812BB55C24 on [BDS_1_UMLRELTNSHPS_ORDER] ([CASEIDENTIFIER1]);


If you look at the first row, it shows "order" which has not been escaped.

Then if you run this SQL script you get the error:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'order'.


If I make the changes detailed the hibernate mapping will look as follows:

<hibernate-mapping auto-import="false">
	<class entity-name="BasicProduct" abstract="false" lazy="false" discriminator-value="com.example.umlrelationships.BasicProduct" table="`BDS_1_UMLRELTNSHPS_BASICPRODCT`">
		<meta attribute="eclassName">BasicProduct</meta>
		<meta attribute="epackage">http://example.com/umlrelationships</meta>
		<id name="bdsId" type="java.lang.Long">
			<column not-null="true" unique="false" name="`BDS_ID`"/>
			<generator class="com.tibco.bds.core.ecore.IdGenerator"/>
		</id>
		<discriminator column="`DTYPE`" type="string"/>
		<version name="bdsVersion" type="java.lang.Long">
			<column not-null="false" unique="false" name="`BDS_VERSION`"/>
		</version>
		<property name="caseIdentifier1" lazy="false" insert="true" update="true" not-null="true" unique="true" type="java.lang.String" index="IDX_1_UMLRELTNSHPS_87CB702C46F">
			<column not-null="true" unique="true" name="`CASEIDENTIFIER1`" length="400" index="IDX_1_UMLRELTNSHPS_87CB702C46F"/>
		</property>
	</class>
	<class entity-name="Order" abstract="false" lazy="false" discriminator-value="com.example.umlrelationships.Order" table="`BDS_1_UMLRELTNSHPS_ORDER`">
		<meta attribute="eclassName">Order</meta>
		<meta attribute="epackage">http://example.com/umlrelationships</meta>
		<id name="bdsId" type="java.lang.Long">
			<column not-null="true" unique="false" name="`BDS_ID`"/>
			<generator class="com.tibco.bds.core.ecore.IdGenerator"/>
		</id>
		<discriminator column="`DTYPE`" type="string"/>
		<version name="bdsVersion" type="java.lang.Long">
			<column not-null="false" unique="false" name="`BDS_VERSION`"/>
		</version>
		<property name="caseIdentifier1" lazy="false" insert="true" update="true" not-null="true" unique="true" type="java.lang.String" index="IDX_1_UMLRELTNSHPS_8F1FC523670">
			<column not-null="true" unique="true" name="`CASEIDENTIFIER1`" length="400" index="IDX_1_UMLRELTNSHPS_8F1FC523670"/>
		</property>
		<one-to-one name="`PRODUCT`" entity-name="Product" cascade="merge,persist,save-update,lock,refresh" lazy="false" property-ref="`ORDER`"/>
	</class>
	<subclass entity-name="Product" abstract="false" lazy="false" extends="BasicProduct" discriminator-value="com.example.umlrelationships.Product">
		<meta attribute="eclassName">Product</meta>
		<meta attribute="epackage">http://example.com/umlrelationships</meta>
		<many-to-one name="`ORDER`" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false" lazy="false" insert="true" update="true"/>
	</subclass>
</hibernate-mapping>


Which in turn will produce the following SQL:

create table [BDS_1_UMLRELTNSHPS_BASICPRODCT] ([BDS_ID] numeric(19,0) not null, [DTYPE] nvarchar(255) not null, [BDS_VERSION] numeric(19,0) null, [CASEIDENTIFIER1] nvarchar(400) not null unique, [ORDER] numeric(19,0) null, primary key ([BDS_ID]));
create table [BDS_1_UMLRELTNSHPS_ORDER] ([BDS_ID] numeric(19,0) not null, [DTYPE] nvarchar(255) not null, [BDS_VERSION] numeric(19,0) null, [CASEIDENTIFIER1] nvarchar(400) not null unique, primary key ([BDS_ID]));
create index IDX_1_UMLRELTNSHPS_87CB702C46F on [BDS_1_UMLRELTNSHPS_BASICPRODCT] ([CASEIDENTIFIER1]);
alter table [BDS_1_UMLRELTNSHPS_BASICPRODCT] add constraint FK1B38D06A90E265C foreign key ([ORDER]) references [BDS_1_UMLRELTNSHPS_ORDER];
create index IDX_1_UMLRELTNSHPS_8F1FC523670 on [BDS_1_UMLRELTNSHPS_ORDER] ([CASEIDENTIFIER1]);


Which now runs OK, as the Order has been escaped as expected.

I hope this helps, it is very possible that I have added the fix in the incorrect location, and there is a better location to add this.

Thanks, Rob

Re: [Teneo] DB Keywords not always escapes [message #1121280 is a reply to message #1121265] Mon, 30 September 2013 13:03 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

That said - although the changes that I highlighted work in this single case - they do appear to break other areas of eCore -> Hibernate mappings Sad

I would very much appreciate some pointers and suggestions in this area if you are happy to give them!

Thanks, Rob
Re: [Teneo] DB Keywords not always escapes [message #1121422 is a reply to message #1121208] Mon, 30 September 2013 15:58 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Martin,

More research, and a bit better hibernate on my part!

I believe the current line that is generate in the hibernate mapping file:

<many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false" lazy="false" insert="true" update="true"/>


Needs to actually be:

<many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false" lazy="false" insert="true" update="true" column="`ORDER`"/>


(So the column=... part)

But I have to say, I'm not quite sure where this would need to be added in the Teneo code - I have tried a few places - but all my solutions are a little hacky - also, I guess we need to pay attention to some naming annotations at this point?

Any ideas?

Thanks for your assistance and patience!
Re: [Teneo] DB Keywords not always escapes [message #1121474 is a reply to message #1121422] Mon, 30 September 2013 17:05 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rob,
Thanks for your patience :-)! Have you tried to add a @JoinColumn annotation to force a specific column name or let
Teneo escape it?

gr. Martin

On 09/30/2013 05:58 PM, Rob Mising name wrote:
> Hi Martin,
>
> More research, and a bit better hibernate on my part!
>
> I believe the current line that is generate in the hibernate mapping file:
>
>
> <many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false"
> lazy="false" insert="true" update="true"/>
>
> Needs to actually be:
>
>
> <many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false"
> lazy="false" insert="true" update="true" column="`ORDER`"/>
>
> (So the column=... part)
>
> But I have to say, I'm not quite sure where this would need to be added in the Teneo code - I have tried a few places -
> but all my solutions are a little hacky - also, I guess we need to pay attention to some naming annotations at this point?
>
> Any ideas?
>
> Thanks for your assistance and patience!
>


--

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] DB Keywords not always escapes [message #1122114 is a reply to message #1121474] Tue, 01 October 2013 08:41 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Martin Taal wrote on Mon, 30 September 2013 18:05

Have you tried to add a @JoinColumn annotation to force a specific column name or let Teneo escape it?


Thanks Martin, I think you may have discovered a much better work around!

1) Without any annotation

<many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false" lazy="false" insert="true" update="true"/>


2) With: @Column(name="ORDER")

<many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false" lazy="false" insert="true" update="true"/>


3) With: @JoinColumn(name="ORDER")

<many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false" lazy="false" insert="true" update="true">
	<column not-null="false" unique="false" name="`ORDER`"/>
</many-to-one>


So it looks like @JoinColumn will work for me! So it's now just the case where there is no annotation to set the name where it is missing the escaped column name.

Thank, Rob
Re: [Teneo] DB Keywords not always escapes [message #1122217 is a reply to message #1122114] Tue, 01 October 2013 10:35 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Rob,
Okay good! What I find strange though is that the column tag is not created by default. Afaik Teneo should generate also
all the db schema tags (so no need to set a JoinColumn annotation explicitly). Which version of Teneo are you using?

gr. Martin

On 10/01/2013 10:41 AM, Rob Mising name wrote:
> Martin Taal wrote on Mon, 30 September 2013 18:05
>> Have you tried to add a @JoinColumn annotation to force a specific column name or let Teneo escape it?
>
>
> Thanks Martin, I think you may have discovered a much better work around!
>
> 1) Without any annotation
>
> <many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false"
> lazy="false" insert="true" update="true"/>
>
>
> 2) With: @Column(name="ORDER")
>
> <many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false"
> lazy="false" insert="true" update="true"/>
>
>
> 3) With: @JoinColumn(name="ORDER")
>
> <many-to-one name="order" entity-name="Order" cascade="merge,persist,save-update,lock,refresh" not-null="false"
> lazy="false" insert="true" update="true">
> <column not-null="false" unique="false" name="`ORDER`"/>
> </many-to-one>
>
>
> So it looks like @JoinColumn will work for me! So it's now just the case where there is no annotation to set the name
> where it is missing the escaped column name.
>
> Thank, 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] DB Keywords not always escapes [message #1122221 is a reply to message #1122217] Tue, 01 October 2013 10:43 Go to previous message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Martin Taal wrote on Tue, 01 October 2013 11:35
Hi Rob,
Okay good! What I find strange though is that the column tag is not created by default. Afaik Teneo should generate also
all the db schema tags (so no need to set a JoinColumn annotation explicitly). Which version of Teneo are you using?


Quite an old one I'm afraid - it has to be compatible with EMF 2.4, so we are on 1.0.1 of Teneo Sad

Previous Topic:[CDO/Net4j] Sound check if TCPAcceptor could have been activated
Next Topic:[CDO] NPE in CDOResourceImpl.basicSetResource
Goto Forum:
  


Current Time: Fri Mar 29 07:35:36 GMT 2024

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

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

Back to the top