I'm using Hibernate via JPA api. When I try run this code:
Code:
EntityManager em = getEM();
User uu = new User();
em.persist(uu);
uu.setLogin("qqq");
em.getTransaction().begin();
em.getTransaction().commit(); // Exception: login is null
it fails because of the DB constraint "Login not null", so my setLogin() call was not detected by hibernate. But when I change the property before persisting it works fine:
Code:
EntityManager em = getEM();
User uu = new User();
uu.setLogin("qqq");
em.getTransaction().begin();
em.persist(uu);
em.getTransaction().commit(); // commit successful
Is it a bug in hibernate? When should I call persist() method?
Note that the same code runs fine using EclipseLink and OpenJPA.