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?