-->
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.  [ 4 posts ] 
Author Message
 Post subject: Cascade Performance issue
PostPosted: Mon Dec 11, 2006 1:23 am 
Newbie

Joined: Mon Dec 11, 2006 12:43 am
Posts: 2
Location: Mumbai
Hi ,


I have a design/performance problem due to cascade(save-update) -

Stock object has a collection of Options (1000+) objects.
Stock also has a Map of Indicator objects(about 20)

Both the above have cascade="save-update"

Now I add new Indicators to Stock's map and save Stock(to cascade Indicators).
This obviously cascades all Option objects too.

The save process is very very slow as entire tree is cascaded .

Cannot remove Options cascade.

Can anyone advise alternatives/better design to add new Indicator to Stock in an efficient manner - JDBC?

Using Hibernate 3.1

Any hints appreciated.
B.Rgds,


Top
 Profile  
 
 Post subject: Re: Cascade Performance issue
PostPosted: Mon Dec 11, 2006 1:51 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
sandhuks wrote:
Stock object has a collection of Options (1000+) objects.
Stock also has a Map of Indicator objects(about 20)

Both the above have cascade="save-update"

Now I add new Indicators to Stock's map and save Stock(to cascade Indicators).
This obviously cascades all Option objects too.

The save process is very very slow as entire tree is cascaded .

Cannot remove Options cascade.


As I understand, you're adding Indicators but saving stock objects, so why don't you just pass Indicators objects to session.save() (or persist()).

Have you activated the SQL output ? (show_sql=true), if not, you should do it. (Note that oe should always develop with Hibernate with sql logs activated.)

Depending on which collection you chose to map your indicators, I guess Hibernate is doing some selects to diff the collection of indicators in the stock object. So, saving directly the concerned objects would allow Hibernate to only insert those new objects.

To sum up, instead of :

Code:
yourStock.add(yourIndicator1);
yourStock.add(yourIndicator2);
session.save(yourStock);


Try doing :
Code:
session.save(yourIndicator1);
session.save(yourIndicator2);

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 2:02 am 
Newbie

Joined: Mon Dec 11, 2006 12:43 am
Posts: 2
Location: Mumbai
Indicators is Map in Stock - stock.getIndicators().put("ind1",indicator);

so need save stock in any case :-(

Tks for any hints,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 3:54 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
sandhuks wrote:
Indicators is Map in Stock - stock.getIndicators().put("ind1",indicator);

so need save stock in any case :-(

Tks for any hints,


Anyway, did you have a look in the logs ? Does it trigger a lot of SQL output as I spoke about? something that would explain the time it takes. In fact, you know what is added, but Hibernate is not magic, it needs to checkl everything to see what's changed :-).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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