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);