-->
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: Updating values relatively (balance = balance + value)
PostPosted: Tue Nov 15, 2005 7:11 pm 
Beginner
Beginner

Joined: Tue Oct 25, 2005 2:44 am
Posts: 20
Location: Sydney, Australia
Hi,

I need to update a customers balance relative to what it currently is, i.e. balance = balance + ordervalue (I don't want or care about concurrency checks).

I have placed the balance in a separate class and track the changes made to the balance so I know the relative difference (i.e. ordervalue). How do I get from there to executing sql like the following, or is there a another way?

update customer set balance = balance + 20 where ....

Cheers, Kerry


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 7:06 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can't do it in NHibernate without loading the customer first. Just use direct SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 7:57 pm 
Beginner
Beginner

Joined: Tue Oct 25, 2005 2:44 am
Posts: 20
Location: Sydney, Australia
I have the customer loaded as well, and the relationship between customer and balance is a one to one type relationship. Is there a way to do it now?

Am I able to attach a stored procedure within nhibernate to handle updates? Or is there some form of event I can subscribe to?

I ask because I will just have an ISession.Save(customer) type method which I want to handle the balance as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 12:02 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
If you enable cascading to your balance, then Session.Save(customer) will save its balance also...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 7:47 pm 
Beginner
Beginner

Joined: Tue Oct 25, 2005 2:44 am
Posts: 20
Location: Sydney, Australia
Cool.

Then to make the balance = balance + 20 type call, is it best to use interceptors, would that work or is there another technique?

Thanks


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.