These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Try to insert null into a non-nullable column
PostPosted: Tue Oct 21, 2003 4:52 am 
Newbie

Joined: Tue Oct 21, 2003 3:00 am
Posts: 11
Hi, I'm having problem with the following hibernate mapping, and hoping someone could suggest a solution or a way to work around it.


Code:
<hibernate-mapping>
  <class name="xyz.OwnerOneBO" table="OwnerOneBO">
   
    <id name="id" column="id" type="string"><generator class="assigned"/></id>
    <version column="version" name="version" type="long"/>

    <list name="positionList" cascade="all">
        <key column="OwnerOne_positionList_FK"/>
        <index column="positionList_index"/>
        <element type="adi.gme.datamodel.type.PositionHBType">
            <column name="positionList_x" />
            <column name="positionList_y" />
            <column name="positionList_z" />
        </element>
    </list>

  </class>
</hibernate-mapping>


<hibernate-mapping>
  <class name="xyz.OwnerTwoBO" table="OwnerTwoBO">

    <id name="id" column="id" type="string"><generator class="assigned"/></id>
    <version column="version" name="version" type="long"/>

    <list name="positionList" cascade="all">
        <key column="OwnerTwo_positionList_FK"/>
        <index column="positionList_index"/>
        <element type="adi.gme.datamodel.type.PositionHBType">
            <column name="positionList_x" />
            <column name="positionList_y" />
            <column name="positionList_z" />
        </element>
    </list>

  </class>
</hibernate-mapping>




Using the above mappings I end up with a table called "positionList", and it has six columns namely:

OwnerOne_positionList_FK,
positionList_index,
positionList_x,
positionList_y,
positionList_z,
OwnerTwo_positionList_FK

When I create an instance of OwnerOneBO and added a Position object to the positionList attribute I get the following exception:

net.sf.hibernate.JDBCException: Could not synchronize database state with session: Try to insert null into a non-nullable column in statement [insert into positionList (OwnerOne_positionList_FK, positionList_index, positionList_x, positionList_y, positionList_z) values ('E0ED0A1C-9B62-7A0A-82F7-27CA9A21CD08', 0, 0.0E0, 0.0E0, 0.0E0)]

In other words, it's complaining that I didn't specify "OwnerTwo_positionList_FK" column. But that was indeed my intention to leave the "OwnerTwo_positionList_FK" column as null when the positionList created belongs to OwnerOneBO.

Apart from giving the two list elements distinctive names. Does anyone know if there is property I can set to tell Hibernate to ignore "OwnerTwo_positionList_FK" when I create an instance of OwnerOneBO. Or does anyone know any other way to work around this
issue?

Regards,

KC


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 4:46 pm 
Regular
Regular

Joined: Tue Sep 09, 2003 9:37 pm
Posts: 56
Location: Ogden, Utah, USA
It might be that you have a not null constraint on that column in the database that you didn't intend?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 9:36 pm 
Newbie

Joined: Tue Oct 21, 2003 3:00 am
Posts: 11
TealWren wrote:
It might be that you have a not null constraint on that column in the database that you didn't intend?


Indeed, there is a not null constraint on the "OwnerTwo_positionList_FK" column, but that is something I have no control of.

The problem is I have two different classes: OwnerOneBO and OwnerTwoBOl; and both have a collection(List) of the Position class and they both call this collection(List) attribute as positionList. So I end up with a table with the following columns:

OwnerOne_positionList_FK (Not Null),
positionList_index,
positionList_x,
positionList_y,
positionList_z,
OwnerTwo_positionList_FK (Not Null)

And when I create an instance of OwnerOneBO , the column OwnerTwo_positionList_FK has to be null!

Any one can help? Many thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 11:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
If its possible and normal that that one or the other column will be null, then how is this a valid NOT NULL constraint? Sounds like an FK constraint would be a better choice than a NOT NULL constraint.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 11:36 pm 
Newbie

Joined: Tue Oct 21, 2003 3:00 am
Posts: 11
steve wrote:
If its possible and normal that that one or the other column will be null, then how is this a valid NOT NULL constraint? Sounds like an FK constraint would be a better choice than a NOT NULL constraint.


Sorry, I think I have confused everyone, because I thought it was Hibernate's default to set the FK constrain together with the NOT NULL constraint, and that's why I'm getting the exception:

Try to insert null into a non-nullable column in statement [insert into positionList (OwnerOne_positionList_FK, positionList_index, positionList_x, positionList_y, positionList_z) values ('E0ED0A1C-9B62-7A0A-82F7-27CA9A21CD08', 0, 0.0E0, 0.0E0, 0.0E0)]

Or perhaps that is a default by the Hypersonic Database Engine...? I will check...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 11:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
because I thought it was Hibernate's default to set the FK constrain together with the NOT NULL constraint

But Hibernate does not do anything with constraints; or are you talking about the schema generator?

And besides you would want an FK constraint instead of a NOT NULL constraint.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.