[hibernate-issues] [Hibernate-JIRA] Created: (EJB-419) EntityManager.persist validation: Inconsistent with other JPA Implemetations
Francisco Peredo (JIRA)
noreply at atlassian.com
Fri Mar 20 14:04:38 EDT 2009
EntityManager.persist validation: Inconsistent with other JPA Implemetations
------------------------------------------------------------------------------
Key: EJB-419
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-419
Project: Hibernate Entity Manager
Issue Type: Bug
Affects Versions: 3.3.2.GA
Reporter: Francisco Peredo
With the following JPA @Entity:
@Entity
public class Customer {
private Long id;
private String name;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(nullable=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
And then the following test
@Test
public void persistCustomerInTransaction() throws Exception {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
Customer customer = new Customer();
em.persist(customer);em.getTransaction().commit();
em.close();
}
Where does/should it crash?:
1. At the line em.persist(customer); because the name is configured as nullable=false, and we are trying to persist the Customer instance with a null value in the name property
2. em.getTransaction().commit(); because the name is configured as nullable=false, and we are trying to commit the transaction with a null value in the name property
Turns out... that the answer depends on the JPA provider you are using! If using Hibernate, it crashes at em.persist, but if using EclipseLink, it crashes at em.getTransaction().commit.
I think Hibernate it should validate this kind of things at em.getTransaction().commit() and not at em.persist.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list