-->
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.  [ 2 posts ] 
Author Message
 Post subject: Simple update
PostPosted: Fri Mar 21, 2008 10:57 pm 
Newbie

Joined: Mon Feb 04, 2008 7:24 pm
Posts: 6
Hi.

I created a class with 4 properties (one of them is my pk property). Then I wrote a code to update this object on my database. If I need to update all the four properties all is ok, but suppose I need to update just one of the properties? For example:

Code:
Dim c As New Customer

c.Id = 1
c.Address = "New address here"
c.Name = ? ' I don't need to update this property
c.Birthday = "New date here"

MySession.Update(c)
MySession.Flush


If I simply don't call the Name property I receive an error. How can I tell NHibernate to not update the Name property?

TIA,
rferj


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 23, 2008 8:23 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
That's not the way you use hibernate. Normally you first retrieve the object from the database, then you make your modifications, then you persist your changes. Something like:

Code:
Customer c = session.Get<Customer>(1)
c.Address = "New Address";
c.Birthday = "New Birthday";
session.Flush();


or if you close the session after retrieving the object:

Code:
Customer c = session.Get<Customer>(1)
session.Close();
...
c.Address = "New Address";
c.Birthday = "New Birthday";
...
<get new session>
session.Update(c);
session.Flush();

_________________
--Wolfgang


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