-->
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.  [ 3 posts ] 
Author Message
 Post subject: list-index being set to null
PostPosted: Fri Jan 16, 2009 1:03 am 
Newbie

Joined: Wed Jan 14, 2009 5:55 pm
Posts: 2
Hibernate version: 3.2.6


Name and version of the database you are using: Oracle 10g


Hello,

I’m having trouble with a mapping where I’m not getting the list-index set. The index is always null. Can someone see what is wrong with this mapping: (and I'm only including what what I think is needed because I can't copy/paste--I have to retype this because our development environment is an isolated environment. Let me know if you have an idea but need more.)

Code:
<class name="DummyDataEntity" ...  (used generated id called DUMMY_ID)

<list name="smarties" cascade="all, delete-orphan" inverse="true">
    <key column="DUMMY_ID" />
    <list-index column="SMART_ORDER"/>
    <one-to-many class="Smarty"/>
</list>
...
</class>

<class name="Smarty" table="SMARTY">
   <composite-id>
       <key-many-to-one name="parent"  class="DummyDataEntity">
          <column name="DUMMY_ID" not-null="true"/>
       </key-many-to-one>
       <key-property name="uniqueKey" type="string"/>
   </composite-id>
</class

After saving a DummyDataEntity object, the data in the database looks like this:
Code:
DummyDataEntity:
DUMMY_ID
653   ............


SMARTY:
DUMMY_ID     UNIQUEKEY  SMART_ORDER
653          uk1          <null>
653          uk2          <null>



The database structure needs to stay like this where the child SMARTY table's DUMMY_ID is a foreign key to it's parent DummyDataEntity.DUMMY_ID. That's why Smarty doesn't have an id generator of it's own.

So when I try to load the DummyDataEntity, there are problems because the list order(SMART_ORDER) is null.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2009 3:35 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think the problem is that you have inverse="true" in the <list> mapping. This will make Hibernate ignore the list when updating the database. And the SMART_ORDER column is not mapped in the Smarty class so there is no place for Hibernate to get a value for it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 9:38 am 
Newbie

Joined: Wed Jan 14, 2009 5:55 pm
Posts: 2
Thanks. I think you are right. When I set inverse to false, then the list-index fills in the SMART_ORDER column. However, If I attempt to delete the top level object(DummyDataEntity), I expect it to remove all of the Smarty objects too. But all I get is an exception:

Hibernate operation: could not delete collection [....]; uncategorized SQLException for SQL [update SMARTY set DUMMY_ID=null where DUMMY_ID=?; ..... java.sql.SQLException ORA-1407: cannot update ("SMARTY"."DUMMY_ID") to NULL


So instead of deleting, its attempting to set the id to null.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.