[英]org.hibernate.AnnotationException: Unable to create unique key constraint
I am using hibernate 4.3.5.Final version. 我正在使用休眠4.3.5。最终版本。
To handle reserve words at Database,I used a property in hibernate hibernate.globally_quoted_identifiers = true. 为了在数据库中处理保留字,我在休眠状态下使用了一个属性hibernate.globally_quoted_identifiers = true。
And My pojo class having a unique column and it looks like 而且我的pojo类具有唯一的列,它看起来像
@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 然后,当我的SessionFactoryBean正在加载时,它失败并显示以下错误
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). 在调试过程中,我发现问题是由于添加的属性(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.
当添加此属性时,Hibernate将在单引号后面加上保留字。但是从PhysicalToLogical映射时,它无法将name1与name1映射。因此,我遇到了以上错误。
Can any one suggest how to handle above two cases(reserve words + UniqueConstraint) at a time. 谁能一次建议如何处理以上两种情况(保留字+ UniqueConstraint)。
When hibernate.globally_quoted_identifiers is set, Hibernate expects exact column name. 设置hibernate.globally_quoted_identifiers后,Hibernate需要确切的列名。 Check JPA with Hibernate 3.6.8.Final, PostgresSQL 9.1, SQLGrammarException - configuration issue?
使用Hibernate 3.6.8.Final,PostgresSQL 9.1,SQLGrammarException检查JPA-配置问题? Weird SQL statement for more information.
有关更多信息的怪异SQL语句 。 So according to this, your column name and Table names in the pojo class need to be quoted.
因此,据此,需要引用pojo类中的列名和表名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.