JPA 把欄位名稱全大寫時,Constraint 會抓不到欄位名稱,找不到解決方案的問題

JPA 使用 Hibernate 的實作,把 entity 的 property 用 @Column 指定欄位名稱為全大寫時,若 @Table 使用 @UniqueConstraint,會無法抓到該欄位名稱丟出 Exception.

例如:
Entity 的宣告:

@Entity
@Table(name = "\"STOCK\"" , uniqueConstraints = {@UniqueConstraint (columnNames={"\"ID\"" })})
public class Stock implements Serializable

property 宣告:

@Column(name = "\"ID\"" )
private String id;

會丟出:
Caused by: org.hibernate.AnnotationException: Unable to create unique key constraint ("ID") on table STOCK: database column 'ID' 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)
      at org.hibernate.cfg.Configuration.buildSessionFactory( Configuration.java:1844)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform( EntityManagerFactoryBuilderImpl.java:850)
      ... 30 more

求解?

0 意見: