EJB3.x: 关于@UniqueConstraint标记无效问题
在制定Entity Bean时,设置了该实体的@UniqueConstraint限制。但是对该实体Bean进行部署后,并没有在数据库表中看到对应表字段出现unique限制。这是因为@UniqueConstraint标记必须在自动生成表的情况下才起作用。即,在persistence.xml中将hibernate.hbm2ddl.auto设置为create-drop。否则,唯一性约束限制不会被加入到数据库中。
以下是《JSR 220: Enterprise JavaBeansTM,Version 3.0 Java Persistence API》文档的原文说明:
Type
|
Name
|
Description
|
Default
|
UniqueConstraint[]
|
uniqueConstraints
|
(Optional) Unique constraints that are to be placed on the table. These are only used if table generation is in effect. These constraints apply in addition to any constraints specified by the Column and JoinColumn annotations and constraints entailed by primary key mappings.
|
No additional
constraints
|