Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1.2
Mapping documents:
Code between sessionFactory.openSession() and session.close():
List<Batch> list = getHibernateTemplate().find(
"from Batch batch where creationDate < ?", new Object[]{archivedDate});
System.out.println("*********** finished list with size: " + list.size());
for(Batch b : list) {
System.err.println("*** deleting gbatch with id:" + b.getId());
getHibernateTemplate().delete(b);
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Hibernate: select 0_.batchId as Ba6_1_, message0_.id as id1_, message0_.seq_idx as seq7_1_, message0_.id as id36_0_, message0_.ISIN as ISIN36_0_, message0_.productId as productId36_0_, message0_.rawXml as xml36_0_, message0_.processDate as processD5_36_0_, messagebond0_.sierraBatchId as sierraBa6_36_0_ from Message sierrabond0_ where message0_.BatchId=?
Hi,
I am using Hibernate via Spring (HibernateTemplate) which ultimately calls Session.delete in order to delete my objects..
form the output hibernate gave me (listed above) it turns out that hibernate does a select statement to find all Message childrens before it deletes the Batch object.
I was wondering why hibernate does not do a "delete from Message where message.batchId = Batch.batchId) statement.....
is it because in the mapping document i have specified
Code:
<list name="messages" lazy="true" cascade="all,delete-orphan" inverse="true">
<key column="batchId"/>
<index column="seq_idx"/>
<one-to-many class="Message"/>
</list>
?
or instead is a standard Hib behaviour to do a select statement to retrieve all children of an object before deleting it?
I have read hibernate docs, and they say that session.delete has been deprecated, and to use SQL instead......
shall i go that way? i thought that it was simpler and easier to let hibernate handle automatically the deletion of children when a parent is deleted, but it turns out that the select statement before every deleetion will slow down my app big time, especially when i have large number of chilidrens...
regards
marco
thanks in advance and regards
Marco