views:

36

answers:

1

I'm using GUIDs for the identifier on my objects it is assigned when the entity 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?

+2  A: 

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.

ChssPly76
Thanks, I'll look into it, though I would've thought that the `SaveOrUpdate()` method would hit up the database to see if the ID exists, and save or update it accordingly.
Daniel T.
It won't, but there's nothing preventing you from doing that yourself - you can easily write a method in your DAO that would call `Get()` first and subsequently save or merge your object based on its result.
ChssPly76