-->
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.  [ 1 post ] 
Author Message
 Post subject: List-index not combinable with on-delete="cascade"
PostPosted: Wed Jan 21, 2009 11:09 am 
Newbie

Joined: Mon Jan 19, 2009 6:16 am
Posts: 4
Hello,

The problem is the following:

If i want my mapping to make hibernate handle the list-index, i have to remove inverse="true" and on-delete="cascade" in <list name="hourEntries">

But, if I remove inverse="true" and on-delete="cascade", hibernate doesn't apply an on delete cascade on the foreign key.

Another guy with the same problem hacks in the hibernate source and changes Mappings.Collection.validate() -> http://lists.jboss.org/pipermail/hibern ... 08224.html
but that doesn't seem to work for me and is a dirty solution.

Hibernate: Hibernate 3.3.1.GA
Dialect: org.hibernate.dialect.MySQL5InnoDBDialect
MySQL: 5.0.22

I have the following mappings:

RegistrationEntry (Parent)
Code:
<hibernate-mapping>
    <class name="nl.ncim.timetracking.model.RegistrationEntry" table="registration_entry">
        <id name="registrationEntryID" column="registrationentry_id" unsaved-value="0">
            <generator class="native"/>
        </id>
       
...

      <property name="registrationEntryOrder" column="registrationentry_order" type="int" update="true" insert="true" not-null="true"/>
      
...
      
      <list name="hourEntries" access="field" cascade="all,delete-orphan" lazy="false">
         <key column="registration_entry" on-delete="cascade"/>
              <index column="hourentry_order"/>         
         <one-to-many class="nl.ncim.timetracking.model.HourEntry"  />
      </list>       
      
    </class>
</hibernate-mapping>



HourEntry (Child)
Code:
<hibernate-mapping>
    <class name="nl.ncim.timetracking.model.HourEntry" table="hour_entry">
        <id name="hourEntryID" column="hourentry_id" unsaved-value="0">
            <generator class="native"/>
        </id>     

       ....

      <property name="hourEntryOrder" column="hourentry_order" type="int" update="false" not-null="true"/>

         <many-to-one name="registrationEntry" class="nl.ncim.timetracking.model.RegistrationEntry"
         column="registration_entry" foreign-key="RegistrationEntryFK" not-null="true" />
     </class>
</hibernate-mapping>


If I add on-delete: only inverse one-to-many associations may use on-delete="cascade"
Without on-delete: Cannot delete or update a parent row: a foreign key constraint fails
If i add inverse: IndexOutOfBoundsException when trying to fetch the list

I guess its unneeded, but in the case it helps to clarify, the getter and setter for the hourEntryOrder:

Code:
   public int getHourEntryOrder() {
      RegistrationEntry regEntry = this.getRegistrationEntry();
      
      if(regEntry != null && regEntry.getHourEntries() != null) {
         return regEntry.getHourEntries().indexOf(this);
      } else {
         return 0;
      }
   }

   public void setHourEntryOrder(int hourEntryOrder) {
      //this.hourEntryOrder = hourEntryOrder;
   }



Thanks in advance for any help,
Joost Pastoor


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

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.