[hibernate-issues] [Hibernate-JIRA] Commented: (EJB-419) EntityManager.persist validation: Inconsistent with other JPA Implemetations

Francisco Peredo (JIRA) noreply at atlassian.com
Tue Jun 2 11:01:14 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/EJB-419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33308#action_33308 ] 

Francisco Peredo commented on EJB-419:
--------------------------------------

If nullable=true is defined by the spec as ONLY a hint for schema generation, then... why is used for VALIDATION by org.hibernate.engine.Nullability.checkNullability ? (see more failed by Hibernate tests in the previously referenced forum topic).

And so, a new JIRA, better matching this problem is created.


>  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