-->
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: Load Objet before Delete Performance bottleneck
PostPosted: Tue Jan 06, 2004 1:18 pm 
Beginner
Beginner

Joined: Mon Nov 24, 2003 5:39 am
Posts: 26
Location: France
Hello,

I am a bit stuck here. I have looked through the documentation but failed to find the answer to the following problem:

I have a relationship between a parent object and two child objects. I want the child objects deleted from persistence when I delete the parent. This works fine except that Hibernate loads the child objects before it deletes them. This adds two additional select statements to the process and creates a large overhead. What have I overlooked? Is there a way to avoid these additional selects?

Here's the mapping, code, and SQL output:

MAPPING

<hibernate-mapping default-cascade="none" auto-import="true">
<class name="com.mycompany.hibercool.example.dto.PersonHB" table="PER_PERSONNE" dynamic-update="false" dynamic-insert="false" mutable="true" polymorphism="implicit" batch-size="1" select-before-update="false" optimistic-lock="version">
<id name="id" column="PK_PER_ID" type="java.lang.Long" unsaved-value="null">
<generator class="assigned" />
</id>
<property name="cellularNumber" type="java.lang.String" update="true" insert="true" column="PER_CELLULAR_NUMBER" length="12" not-null="false" unique="false" />
<property name="email" type="java.lang.String" update="true" insert="true" column="PER_EMAIL" length="30" not-null="false" unique="false" />
<set name="etatsCivils" lazy="true" inverse="true" cascade="delete" sort="unsorted" batch-size="1" outer-join="auto">
<key column="FK_PER_ID" />
<one-to-many class="com.mycompany.hibercool.example.dto.EtatCivilHB" />
</set>
<set name="habilitationsSages" lazy="true" inverse="true" cascade="delete" sort="unsorted" batch-size="1" outer-join="auto">
<key column="FK_PER_ID" />
<one-to-many class="com.mycompany.hibercool.example.dto.HabilitationSagesHB" />
</set>
<property name="phoneNumber" type="java.lang.String" update="true" insert="true" column="PER_PHONE_NUMBER" length="12" not-null="false" unique="false" />

</class>
</hibernate-mapping>


JAVA

int nb = session.delete("from com.mycompany.hibercool.example.dto.PersonHB person where person.id = " + id);


SQL OUTPUT

17:49:50,174 INFO [STDOUT] Hibernate: select personhb0_.PK_PER_ID as PK_PER_ID, personhb0_.PER_CELLULAR_NUMBER as PER_CELL2_, personhb0_.PER_EMAIL as PER_EMAIL, personhb0_.PER_PHONE_NUMBER as PER_PHON4_ from PER_PERSONNE personhb0_ where (personhb0_.PK_PER_ID=100000048564 )
17:49:50,420 INFO [STDOUT] Hibernate: select etatscivil0_.PK_ETC_ID as PK_ETC_ID__, etatscivil0_.FK_PER_ID as FK_PER_ID__, etatscivil0_.PK_ETC_ID as PK_ETC_ID0_, etatscivil0_.ETC_YEAR as ETC_YEAR0_, etatscivil0_.ETC_BIRTHNAME as ETC_BIRT3_0_, etatscivil0_.ETC_FIRSTNAME as ETC_FIRS4_0_, etatscivil0_.ETC_LASTNAME as ETC_LAST5_0_, etatscivil0_.ETC_TITLE as ETC_TITLE0_, etatscivil0_.FK_PER_ID as FK_PER_ID0_ from ETC_ETAT_CIVIL etatscivil0_ where etatscivil0_.FK_PER_ID=?
17:49:50,433 INFO [STDOUT] Hibernate: select habilitati0_.PK_HAS_ID as PK_HAS_ID__, habilitati0_.FK_PER_ID as FK_PER_ID__, habilitati0_.PK_HAS_ID as PK_HAS_ID0_, habilitati0_.HAS_CODE_DSF as HAS_CODE2_0_, habilitati0_.HAS_YEAR as HAS_YEAR0_, habilitati0_.FK_PER_ID as FK_PER_ID0_ from HAS_HABILITATION_SAGES habilitati0_ where habilitati0_.FK_PER_ID=?

17:49:50,438 INFO [STDOUT] Hibernate: delete from ETC_ETAT_CIVIL where PK_ETC_ID=?
17:49:50,440 INFO [STDOUT] Hibernate: delete from HAS_HABILITATION_SAGES where PK_HAS_ID=?
17:49:50,455 INFO [STDOUT] Hibernate: delete from PER_PERSONNE where PK_PER_ID=?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No, Child objects may also have cascade delete to other objects or may implement particular lifcecycle/interceptor : it has to be loaded

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Point to improve
PostPosted: Wed Jan 07, 2004 4:40 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 5:39 am
Posts: 26
Location: France
I would say that since Hibernate loads a mapping, it should know that there are no further children in the relationship. It should also be possible to detect or at least configure an option that tells that no lifecycle methods are being implemented.

I think this is an important point to improve as it would result in large performance gains.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 5:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I know Gavin already answered (in a more detailed manner) this question before (dev list or in forum ?). He may want to do it again (i'm interested :) ).

_________________
Emmanuel


Top
 Profile  
 
 Post subject: where?
PostPosted: Wed Jan 07, 2004 5:49 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 5:39 am
Posts: 26
Location: France
you wouldn't know where? I having been searching for quite a while on this topic and was suprised that I couldn't find any discussions on this topic.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 6:11 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
At least this one (not very useful though)
http://forum.hibernate.org/viewtopic.php?t=925732&highlight=load+delete
I would add version/timestamp to Gavin's list.

If you really want perf gain, then use the underlying connection...

Add it to Jira and let people vote for it.

_________________
Emmanuel


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.