[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-4151) nullable=true is ONLY a hint for schema generation, but Hibernate uses it for validation

Emmanuel Bernard (JIRA) noreply at atlassian.com
Fri Nov 13 10:01:09 EST 2009


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bernard resolved HHH-4151.
-----------------------------------

    Resolution: Duplicate

This has been fixed with the work I've done to integrate Bean Validation. See HHH-3898

> nullable=true is ONLY a hint for schema generation, but Hibernate uses it for validation
> ----------------------------------------------------------------------------------------
>
>                 Key: HHH-4151
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4151
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: entity-manager
>            Reporter: Francisco Peredo
>
> With the following JPA @Entity (note the @Basic(optional=true), @Column(nullable=false) at the getName method):
> @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;
> }
> @Basic(optional=true)
> @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();
> }
> What exception should be the root cause of this problem?
> According to the spec @Column(nullable=false) is JUST a schema generation hint, and Hibernate should NOT use it for object level validation, so it should crash with a java.sql.SQLException as the root exception, and not with a org.hibernate.PropertyValueException thrown by org.hibernate.engine.Nullability.checkNullability.

-- 
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