我想在 JPA/Playframework 中测试 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;
但是每次都测试失败,因为没有任何异常发生。