-->
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.  [ 8 posts ] 
Author Message
 Post subject: Performance problem on a one to many cascade relation
PostPosted: Tue Feb 26, 2008 1:16 pm 
Newbie

Joined: Tue Feb 26, 2008 12:51 pm
Posts: 4
Hi
I've a performance problem with a one to many relation and cascade setting.
The structure is
- one header
- many rows

the declararion is

Code:
@Entity
@Table(name="HEAD")
public class Head implements Serializable {

    private Long id;
    @Id
    @Column(name="HEADID", length=11)
    ...

    private List<Row> rows;
    @OneToMany(mappedBy="despatchAdvice", cascade=CascadeType.ALL)
    ...
}

@Entity
@Table(name="ROW")
public class Row implements Serializable {
   
    private Long id;
    @Id
    @Column(name="ROWID", length=11)
    ...
   
    private Head ;
    @ManyToOne
    @JoinColumn(name="HEDADID", nullable=false)
    @Fetch(FetchMode.JOIN)
    ...
}


when i execute the following code

Code:
session.update(head);
session.flush();


where head is an Head's instance, attached to N rows , and I only modified the head, hibernate do a multiple select for each head's row and then an head update.

if i cache the rows with
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
the N select are substituted with N update.
(I found this case on http://forum.hibernate.org/viewtopic.php?t=982390&highlight= )

My questions are
- in the first case, is there any way to force hibernate to do a single select instead a multiple select?
- in the second case, is there any way to force hibernate to do only the necessary updates

Thanxs

Stefano


Top
 Profile  
 
 Post subject: Re: Performance problem on a one to many cascade relation
PostPosted: Tue Feb 26, 2008 1:31 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
How do the updates look like?




Farzad-


Top
 Profile  
 
 Post subject: Re: Performance problem on a one to many cascade relation
PostPosted: Tue Feb 26, 2008 1:46 pm 
Newbie

Joined: Tue Feb 26, 2008 12:51 pm
Posts: 4
farzad wrote:
How do the updates look like?

Farzad-


They look like

DEBUG AbstractBatcher : update HEAD set FIELD1=?, ...FIELDN=? where HEADID=?
DEBUG AbstractBatcher : update ROW set FIELDA=?, ... FIELDZ=? where ROWID=?
DEBUG AbstractBatcher : update ROW set FIELDA=?, ... FIELDZ=? where ROWID=?
....
DEBUG AbstractBatcher : update ROW set FIELDA=?, ... FIELDZ=? where ROWID=?

Stefano


Top
 Profile  
 
 Post subject: Re: Performance problem on a one to many cascade relation
PostPosted: Tue Feb 26, 2008 2:52 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
This looks like a full update. do you have any modifications in the row objects? Can you set dynamicUpdate for the Row class and see what exactly needs to be updated?



Farzad-


Top
 Profile  
 
 Post subject: Re: Performance problem on a one to many cascade relation
PostPosted: Thu Feb 28, 2008 1:24 pm 
Newbie

Joined: Tue Feb 26, 2008 12:51 pm
Posts: 4
farzad wrote:
This looks like a full update. do you have any modifications in the row objects? Can you set dynamicUpdate for the Row class and see what exactly needs to be updated?



Farzad-


I changed the ROW's annotation in
Code:
@Entity
@Table(name="ROW")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@org.hibernate.annotations.Entity(dynamicUpdate = true)
public class Row implements Serializable {


but the updates don't change

seems to me that the key is
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
if I use it Hibernate does a sequence of updates (rows and head), if I don't use it Hibernate does a sequence of select for each row and an update on the head.
If really the rows was changed in second case, after the rows select, we must have a row update

I think I don't really understand the meaning of the cache, maybe the update were only simulated in cache and then if really necessary on the db?

Stefano


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 8:08 pm 
Newbie

Joined: Thu Jan 04, 2007 1:36 pm
Posts: 16
The updates on Rows are happening coz you've set the cascade setting to ALL. You may have to look for a different setting if you know exactly which actions need to be propagated from Head to Row (ex: insert, update, delete, merge, etc)

Regards,
Arun


Top
 Profile  
 
 Post subject: Re: Performance problem on a one to many cascade relation
PostPosted: Thu Feb 28, 2008 10:13 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Umm, there should be something wrong here because with the dynamic update you should not see a full update statement. Give me a sample code that exhibits the problem. I have done a test and it works fine for me so the difference should be the sequence of things that happen in your case. Can you give me a code that exhibits the problem?



Farzad-


Top
 Profile  
 
 Post subject: Re: Performance problem on a one to many cascade relation
PostPosted: Tue Mar 11, 2008 4:37 am 
Newbie

Joined: Tue Feb 26, 2008 12:51 pm
Posts: 4
After many try I understand that the problem is in org.springframework.orm.hibernate3.support.HibernateDaoSupport, I extended this class and used the getHibernateTemplate().find(), that seems to force an update after a succesfull select (on any object in my model!), the code follows:

Code:
String query = "from object obj where obj.field= ?";
List objects= getHibernateTemplate().find(query, fieldvalue);


Anyone has some idea to modify this behaviour? Is this the rigth place to post this kind of question?

Stefano


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