Hello,
I have changed a lot in my mappings lately, to make Hibernate cascade the delete to the RegistrationEntries and HourEntries when a Registration gets deleted.
I got that to work now, but it presented another problem.
When I try to update a Registration, it deletes the Registration afterwards? Im pretty sure I'm not deleting it manually in my code so its proberly something in my mappings.
Any of u have an idea what the problem is?
Thanks very much in advance,
Joost Pastoor
Hibernate version: 3.3.1.GA
Mapping documents:
Registration
Code:
<hibernate-mapping>
<class name="nl.ncim.timetracking.model.Registration" table="registration">
<id name="registrationID" column="registration_id" unsaved-value="0">
<generator class="native"/>
</id>
...
<list name="registrationEntries" cascade="all,delete-orphan" lazy="false" inverse="true">
<key column="registration" on-delete="cascade"/>
<index column="registrationentry_id"/>
<one-to-many class="nl.ncim.timetracking.model.RegistrationEntry"/>
</list>
....
</class>
</hibernate-mapping>
RegistrationEntryCode:
<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>
...
<many-to-one name="registration" foreign-key="RegistrationFK" [color=red]cascade="all"[/color] class="nl.ncim.timetracking.model.Registration" column="registration" update="false" not-null="true"/>
...
<list name="hourEntries" cascade="all,delete-orphan" inverse="true" lazy="false">
<key column="registration_entry" on-delete="cascade"/>
<index column="hourentry_id"/>
<one-to-many class="nl.ncim.timetracking.model.HourEntry" />
</list>
</class>
</hibernate-mapping>
HourEntryCode:
<hibernate-mapping>
<class name="nl.ncim.timetracking.model.HourEntry" table="hour_entry">
<id name="hourEntryID" column="hourentry_id">
<generator class="native"/>
</id>
...
<many-to-one name="registrationEntry" class="nl.ncim.timetracking.model.RegistrationEntry"
column="registration_entry" foreign-key="RegistrationEntryFK" [color=red]cascade="all"[/color] not-null="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
session.clear();
registration = (Registration) session.merge(registration);
Full stack trace of any exception that occurs:None.
Name and version of the database you are using:MySQL client version: 5.0.22
The generated SQL (show_sql=true):Code:
... inserts of all the components in the Registration
Hibernate: insert into hour_entry (hour_type, amount, registration_entry) values (?, ?, ?)
Hibernate: insert into hour_entry (hour_type, amount, registration_entry) values (?, ?, ?)
Hibernate: insert into hour_entry (hour_type, amount, registration_entry) values (?, ?, ?)
Hibernate: insert into hour_entry (hour_type, amount, registration_entry) values (?, ?, ?)
Registration saved or updated.
Hibernate: select registrati0_.registration_id as registra1_2_0_, registrati0_.create_timestamp as create2_2_0_, registrati0_.about_month as about3_2_0_, registrati0_.signed_employee as signed4_2_0_, registrati0_.signed_customer as signed5_2_0_, registrati0_.signed_administration as signed6_2_0_, registrati0_.user_id as user7_2_0_, registrati0_.project as project2_0_, registrati0_.customer as customer2_0_ from registration registrati0_ where registrati0_.registration_id=?
.... lots of selects
Hibernate: select registrati0_.registration_entry as registra7_1_, registrati0_.change_id as change1_1_, registrati0_.change_id as change1_4_0_, registrati0_.changed_field as changed2_4_0_, registrati0_.old_value as old3_4_0_, registrati0_.new_value as new4_4_0_, registrati0_.change_timestamp as change5_4_0_, registrati0_.user_id as user6_4_0_, registrati0_.registration_entry as registra7_4_0_ from registration_change registrati0_ where registrati0_.registration_entry=?
Hibernate: delete from hour_entry where hourentry_id=?
Hibernate: delete from hour_entry where hourentry_id=?
Hibernate: delete from hour_entry where hourentry_id=?
Hibernate: delete from hour_entry where hourentry_id=?
Hibernate: delete from hour_entry where hourentry_id=?
Hibernate: delete from registration_entry where registrationentry_id=?
Debug level Hibernate log excerpt:
Don't know