You should check that your DB constraints are not violated before trying to save your entity. In your case that means querying for an entity with the same name as the one that you are trying to save.
On Fri, Mar 20, 2009 at 6:04 AM, tvbusy <[email protected]> wrote: > > I'm working on an Windows Forms application. And entity is retrieved > from database, passed to UI to let user edit and the save it back to > database. > > I'm having a problem with the name unique constraint. It's like a file > system when there should not be two file with the same name in the > same folder. The constraint is enforced at database level. > > According to my understanding, when I try to save the entity, if the > name is not unique, an exception will be thrown, and I'll have to > throw away the session as well as the object. > > My question is since I have only one instance of the object, and the > UI is bound to the instance of entity, how should I handle this? > > I did try adding manual code to clone the entity and save the clone > with another session so that if there's an exception, I still have my > original entity. The problem with this approach is the UI is bound to > the main entity instance, is there anyway that I can tell NHibernate > to populate saved data (ID and timestamps) to the main entity instance? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
