[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2743) NOT NULL columns for "nullable=false" properties not always correct

Andreas Schildbach (JIRA) noreply at atlassian.com
Tue Jul 24 13:41:52 EDT 2007


NOT NULL columns for "nullable=false" properties not always correct
-------------------------------------------------------------------

                 Key: HHH-2743
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2743
             Project: Hibernate3
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.4.sp1
            Reporter: Andreas Schildbach


When Hibernate creates a schema for a "table-per-class-hierarchy" mapping, it does not take into account that some properties might only exist on single branches of that hierarchy.

Have a look at the attached example (Maven2: mvn eclipse:eclipse to create an eclipse project).

Classes A and B extend Base. Class A defines a property "a", and B defines b - both with "nullable = false". Hibernate then creates a "NOT NULL" column for those properties. I think this is not correct, because even if instances of A always have that property set it might still be NULL (for instances of B) in the database due to the table-per-class-hierarchy mapping.

Here is what happens if you start "ProblemTest":

"Attempt to insert null into a non-nullable column: column: B table: BASE in statement [insert into Base (id, a, class) values (null, ?, 'a')]"

This is the schema that has been created by Hibernate for HSQLDB:

create table Base
(
  class varchar(31) not null,
  id integer generated by default as identity (start with 1),
  a integer not null,
  b integer not null,
  primary key (id)
)


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