my test cases are indicating that @Basic(optional=false) and @Persistent(nullValue=NullValue.EXCEPTION) are not enforced in 2.3.7_08 or that i have failed to understand how to annotate. example:
@Entity
public class Request
{
public Request() { }
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Unique
@Persistent(nullValue=NullValue.EXCEPTION)
private String username;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
}
public class RegressionTest
{
/**
*/
@Test
public void regressionTest()
{
EntityManagerFactory emf = Persistence.createEntityManagerFactory("target/test.odb;drop");
EntityManager em = emf.createEntityManager();
EntityTransaction tr = em.getTransaction();
Request r = new Request();
r.setUsername(null);
//try {
tr.begin();
em.persist(r);
tr.commit();
//}
//catch (...) { }
em.close();
emf.close();
}
}
i am able to run `mvn clean && mvn test` with success. the DB explorer shows the Request object in the database with username=null. the target/ directory is wiped out by `mvn clean` so i am certain a schema change is taking effect. running `mvn test` twice in a row without a clean between them does successfully violate the @Unique constraint:
[ObjectDB 2.3.7] javax.persistence.RollbackException Failed to commit transaction: Unique constraint (org.wroth.ws.signup.Request[username]) failed: Attempt to reuse an existing value (null) (error 613) at com.objectdb.jpa.EMImpl.commit(EMImpl.java:279)