简体   繁体   English

org.hibernate.AnnotationException:无法创建唯一的键约束

[英]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.

相关问题 获取 org.hibernate.AnnotationException - Getting org.hibernate.AnnotationException 无法构建Hibernate SessionFactory,由以下原因引起:org.hibernate.AnnotationException: - Unable to build Hibernate SessionFactory, Caused by: org.hibernate.AnnotationException: org.hibernate.AnnotationException:没有为实体指定标识符 - org.hibernate.AnnotationException: No identifier specified for entity Junit-org.hibernate.AnnotationException引起的ExceptionInInitializerError - Junit - ExceptionInInitializerError caused by org.hibernate.AnnotationException org.hibernate.AnnotationException映射错误 - org.hibernate.AnnotationException Mapping Error 引起:org.hibernate.AnnotationException: @OneToOne 或 @ManyToOne on - Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on org.hibernate.AnnotationException: @OneToOne 或 @ManyToOne - org.hibernate.AnnotationException: @OneToOne or @ManyToOne org.hibernate.AnnotationException:从Y引用X的外键具有错误的列数。 应该是2 - org.hibernate.AnnotationException: A Foreign key refering X from Y has the wrong number of column. should be 2 org.hibernate.AnnotationException:外键引用的列数错误。 应该是2 - org.hibernate.AnnotationException: A Foreign key refering has the wrong number of column. should be 2 双向休眠-org.hibernate.AnnotationException:未知的mappingBy in:错误 - bidirectional hibernate - org.hibernate.AnnotationException: Unknown mappedBy in: error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM