-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem with quoted fieldnames in version 3.5.4
PostPosted: Wed Aug 04, 2010 11:28 am 
Beginner
Beginner

Joined: Wed Sep 03, 2003 9:31 am
Posts: 26
Hi. Recently I upgraded to version 3.5.4 and all my mappings ate done using Hibernate Annotations.

After the upgrade I started to have a problem with some ManyToOne relationships with field names containing quotation marks. I need the quotation marks because some field names are named like customer-id instead of customer_id. First of all, I cannot remove the "-" from the field names (not my choice), so I NEED the quotation marks or the database won't recognize the field names.

I wrote some code to illustrate the problem:

The tables (HSQLDB):

Code:
CREATE MEMORY TABLE BEAN1(ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(30))
CREATE MEMORY TABLE BEAN2(ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(30),"ID-BEAN1" INTEGER)


The entities:

Code:
@Entity
public class Bean1 {
   @Id private Integer id;
   private String name;
   ...getters & setters...
}

@Entity
public class Bean2 {
   @Id private Integer id;
   private String name;

   @Column(name="\"id-bean1\"")
   private Integer idBean1;

   @ManyToOne(fetch=FetchType.LAZY)
   @JoinColumn(name="\"id-bean1\"", insertable=false, updatable=false)
   private Bean1 bean1;

   ...getters & setters...
}


The generated exception:

Code:
Exception in thread "main" org.hibernate.DuplicateMappingException:  Table [Bean2] contains phyical column name [`id-bean1`] represented by different logical column names: [`id-bean1`], ["id-bean1"]
   at org.hibernate.cfg.Configuration$MappingsImpl$TableColumnNameBinding.bindPhysicalToLogical(Configuration.java:2691)
   at org.hibernate.cfg.Configuration$MappingsImpl$TableColumnNameBinding.addBinding(Configuration.java:2664)
   at org.hibernate.cfg.Configuration$MappingsImpl.addColumnBinding(Configuration.java:2708)
   at org.hibernate.cfg.Ejb3JoinColumn.addColumnBinding(Ejb3JoinColumn.java:518)
   at org.hibernate.cfg.Ejb3Column.linkWithValue(Ejb3Column.java:298)
   at org.hibernate.cfg.annotations.TableBinder.linkJoinColumnWithValueOverridingNameIfImplicit(TableBinder.java:490)
   at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:428)
   at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:111)
   at org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:541)
   at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:523)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:380)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1377)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)


Again, when I remove the quotation marks, the mappings are processed fine, but the queries doesn't work. Is this a bug or am I missing something here?

Any help will be appreciated. Thanx.


Top
 Profile  
 
 Post subject: Re: Problem with quoted fieldnames in version 3.5.4
PostPosted: Wed Aug 04, 2010 11:48 am 
Beginner
Beginner

Joined: Wed Sep 03, 2003 9:31 am
Posts: 26
Sorry for the unecessary post. I found another post explaining about the backticks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.