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.