UnhandledExcepSean
UnhandledExcepSean

Reputation: 12804

How can I make NHibernate use database constraints to change processing order?

I have a database table with a unique constraint on a foreign key (FK) field and a date field to prevent there from ever being the same date for a given FK. I am using NHibernate (1.2 if relevant) to save two records to the table for the same FK in a single transaction. One was already present with a NULL date and is being updated to have a real date; and the other is an insert with a NULL date. What seems to happen is that NHibernate is trying to insert before update which is violating the constraints (same FK and NULL date).

Without breaking up the save into multiple parts, is there something that can be added to the mapping to make NHibernate realize that inserting before updating would violate the constraint?

Upvotes: 0

Views: 185

Answers (1)

Firo
Firo

Reputation: 30813

AFAIK there is no such thing as to specify the order of operations on Flush(). However you can put the whole operation into a transaction and call session.Flush(); after the change of your model and then use Save() SaveOrUpdate().

Upvotes: 2

Related Questions