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

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


nullable=true is ONLY a hint for schema generation, but Hibernate uses it for validation
----------------------------------------------------------------------------------------

                 Key: EJB-441
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-441
             Project: Hibernate Entity Manager
          Issue Type: Bug
    Affects Versions: 3.3.2.GA
            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