[hibernate-issues] [Hibernate-JIRA] Closed: (EJB-419) EntityManager.persist validation: Inconsistent with other JPA Implemetations
Gavin King (JIRA)
noreply at atlassian.com
Wed May 27 18:18:13 EDT 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/EJB-419?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gavin King closed EJB-419.
--------------------------
Resolution: Rejected
Hibernate' behavior is correct. nullable=true is defined by the spec as a hint for schema generation.
http://java.sun.com/javaee/5/docs/api/javax/persistence/Column.html#nullable()
For object-level validation, use optional=false:
http://java.sun.com/javaee/5/docs/api/javax/persistence/Basic.html#optional()
And please, before raising bug reports, try reading the spec. Thanks.
> 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