0
我想在JPA/Playframework测试的UniqueConstraint:JPA测试的UniqueConstraint
@Test
public void saveWithTitleNotUnique() { // not unique title
Software software1 = builder.template1().withTitle("title1").create();
Software software2 = builder.template1().withTitle("title1").create();
software1.save();
try {
software2.save();
fail("software.title is not unique");
} catch (Exception ex) {}
}
...
@Entity
public class Software extends Model {
@Column(unique = true)
public String title;
但测试失败每一次,因为没有任何异常发生。
我是通过构建器创建的。在create()方法里面有一个新的Software()。所以,这不是重点。 – ses