Reputation: 5657
I am using hibernate 4.3.5.Final version.
To handle reserve words at Database,I used a property in hibernate hibernate.globally_quoted_identifiers = true.
And My pojo class having a unique column and it looks like
@Entity
@Table(name="theme1"
,catalog="theme2"
, uniqueConstraints = @UniqueConstraint(columnNames={"name1"})
public class Theme1 implements java.io.Serializable {
@Id @GeneratedValue(strategy=IDENTITY)
private Integer id;
@Column(name="name1", unique=true, nullable=false, length=32)
private String name1;
.....
Then when my SessionFactoryBean is loading it is failing with below error
Caused by: org.hibernate.AnnotationException: Unable to create unique key constraint (name1) on table theme1: database column 'name1' not found. Make sure that you use the correct column name which depends on the naming strategy in use (it may not be the same as the property name in the entity, especially for relational types)
at org.hibernate.cfg.Configuration.buildUniqueKeyFromColumnNames(Configuration.java:1682)
at org.hibernate.cfg.Configuration.buildUniqueKeyFromColumnNames(Configuration.java:1614)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1450)
In the debugging process,I find issue is because of the property I add (hibernate.globally_quoted_identifiers). When this property is added,Hibernate will append single quotes to handle reserved words.But while mapping from PhysicalToLogical,it is failed to map 'name1' with name1.Hence I got above error.
Can any one suggest how to handle above two cases(reserve words + UniqueConstraint) at a time.
Upvotes: 0
Views: 3894
Reputation: 11
When hibernate.globally_quoted_identifiers is set, Hibernate expects exact column name. Check JPA with Hibernate 3.6.8.Final, PostgresSQL 9.1, SQLGrammarException - configuration issue? Weird SQL statement for more information. So according to this, your column name and Table names in the pojo class need to be quoted.
Upvotes: 1