EJB3.x: 關(guān)于@UniqueConstraint標(biāo)記無(wú)效問(wèn)題
在制定Entity Bean時(shí),設(shè)置了該實(shí)體的@UniqueConstraint限制。但是對(duì)該實(shí)體Bean進(jìn)行部署后,并沒(méi)有在數(shù)據(jù)庫(kù)表中看到對(duì)應(yīng)表字段出現(xiàn)unique限制。這是因?yàn)?#64;UniqueConstraint標(biāo)記必須在自動(dòng)生成表的情況下才起作用。即,在persistence.xml中將hibernate.hbm2ddl.auto設(shè)置為create-drop。否則,唯一性約束限制不會(huì)被加入到數(shù)據(jù)庫(kù)中。
以下是《JSR 220: Enterprise JavaBeansTM,Version 3.0 Java Persistence API》文檔的原文說(shuō)明:
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
|