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.  [ 5 posts ] 
Author Message
 Post subject: Cascade optimization question
PostPosted: Thu Jul 06, 2006 10:36 am 
Newbie

Joined: Wed Mar 22, 2006 4:47 pm
Posts: 5
Ok, I have a question about cascading updates in my WinForms app. I have things setup as follows:

- Master / detail relationship (bag) with inverse="true" and cascade="all"
- In my UI, I create a session to load my object and populate UI elements, then immediately close it, giving control over to the user.
- When the user hits the Save button, I create a brand new session and call Update on my object to push changes back to the DB which all works fine.

Now, NH seems to be performing an update statement for every item in my collection, regardless of whether or not it has changed. I know that NH has no way of knowing (because I'm effectively using a brand new session to do my update) which of my items is "dirty" and therefore has to do this.

So my question is this: should I be using a disconnected session instead of a brand new session for the update? This would allow NH to determine the dirty state of the collection items and only update as necessary. Or should I be manually determining the dirty state of my children and not be relying on the cascading feature of NH?

I'd pretty much decided against disconnected sessions due to problems with stale data amongst other things. Has anyone done anything similar to this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 11:21 am 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
There is an option in your hbm.xml file that says dynamic-update=true and dynamic-insert=true.

By default these are set to false (I belive). Setting these to true will ensure that insert/update statements will only include the things that have been changed


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 11:27 am 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
gcook1@shaw.ca wrote:
There is an option in your hbm.xml file that says dynamic-update=true and dynamic-insert=true.

By default these are set to false (I belive). Setting these to true will ensure that insert/update statements will only include the things that have been changed



Sorry, I've stated something you were already aware of. I've used the cascade option and it works fine for me with the dynamic-update=true.

You also want a new session for each call to the DB to avoid prolonged table locking...

My opinion is if you need to manage the state (or knowledge of the state of your objects) on your own instead of relying on the ORM tool for you, I'd advise not using that ORM tool.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 12:39 pm 
Newbie

Joined: Wed Mar 22, 2006 4:47 pm
Posts: 5
Thanks for your replies...

I can definitely get this working if I use disconnected sessions (which I'm trying to avoid). I guess what I'm trying to find out is if there are any workarounds for my current method, or better still - is there anyone else out there working with the same technique in WinForms (brand new session per database interaction) - how are you handling the cascading updates?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 2:27 pm 
Newbie

Joined: Wed Mar 22, 2006 4:47 pm
Posts: 5
Ok, just one more thing..

Even if I do use disconnected sessions, imagine this scenario:

I attempt a save on my model object and for some reason it throws an exception (maybe I've violated a database constraint). So I fix the problem and attempt a re-save. On this second attempt, I'm going to have to use a fresh session anyway since sessions are not exception safe. So imagine I have 100 items in my detail collection - NH will force 100 seperate updates to be pushed out to the database.

It looks as though I'm going to need a seperate mechanism for storing the dirty state of my objects, but it feels wrong somehow. Any ideas?


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