-->
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: Updating an Assigned ID?
PostPosted: Tue Apr 24, 2007 4:02 pm 
Newbie

Joined: Tue Apr 24, 2007 3:34 pm
Posts: 2
Location: Ohio, USA
Let's say I have a C# class that represents a business entity:

Code:
class Cat {
  string CatID;
  string CatName;
}


CatID is mapped onto table Cats with following structure:

Code:
--------------------
Cats
--------------------
[PK] CATID char(4)
CATNAME varchar(50)
--------------------


(Please disregard the poor table structure. It's something I'm more or less stuck with.)

I have the Cat class mapped onto the Cats table, and the CatID property is marked as id and has an 'assigned' generator. This works fine for adding new cats, deleting existing cats and updating the CatName property.

The stumbling point is what happens when I want to update the CatID property of an existing Cat, a la:

Code:
Cat kittay = (Cat) mySession.Get(typeof(Cat), "chzz");
kittay.CatID = "brgr";


In nHibernate, if I call mySession.Save(kittay), it simply creates a new Cat with the ID of 'brgr', leaving the 'chzz' cat untouched. This makes sense.

If call mySession.Update(kittay), nHibernate blows up saying that it was expecting 1 record, but got 0. This also makes sense, since up to this point, there is no records in the table Cats with CATID of 'brgr'.

What I want to happen is the same effect as would be achieved by the following SQL:

Code:
UPDATE Cats
SET CATID='brgr'
WHERE CATID='chzz';


Are there anything that will let me do that either in hibernate configuration settings, or entity mapping itself, or perhaps some special method in ISession?

I could obviously bypass nHibernate altogether and run the above SQL raw, but I'm trying to avoid that.

Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 3:04 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can't change entity identifiers in NHibernate.


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.