开发者

How do I save a new object using NHibernate when it already has an ID?

开发者 https://www.devze.com 2022-12-12 04:25 出处:网络
I\'m using GUIDs for the identifier on my objects it is assigned when the 开发者_如何学JAVAentity is instantiated. I want to save them using NHibernate and have NHibernate determine whether it\'s a ne

I'm using GUIDs for the identifier on my objects it is assigned when the 开发者_如何学JAVAentity is instantiated. I want to save them using NHibernate and have NHibernate determine whether it's a new object or not. If it's a new object, it should INSERT it, otherwise it should UPDATE it.

How would I do this?


You can do that by adding either version or timestamp to your entity.

Without one of those it's impossible for Hibernate to figure out whether your entity should be inserted or updated since you're using an assigned identifier.

0

精彩评论

暂无评论...
验证码 换一张
取 消