Mapping NHibernate <timestamp> for an Oracle database raises a StaleStateException

We have an NHibernate application that we are migrating from SQL Server to Oracle. Our optimistic concurrency is implemented through the display element <timestamp name="Version">.

The data type of the corresponding column Versionin Oracle is DATE. After saving the object, the C # object remains in memory with a time stamp in milliseconds (for example, 12: 34: 56,789), while the value in the database is accurate only for the second (for example, 12:34:56). Thus, if we try to save the object a second time, we will get a StaleStateException, because the two values ​​do not match.

I tried to fix this by changing the column data type Versionto TIMESTAMP(3). Unfortunately, the C # object and the DB value are still disabled for one millisecond (for example, 12: 34: 56,789 versus 12: 34: 56,788), so the second attempt to save the object still raises a StaleStateException.

What can I do to create a working mapping <timestamp>for an Oracle column of type DATEor TIMESTAMPso that the same object can be saved multiple times?

Thank.

- Brian

+3
source share
1 answer

TIMESTAMP (7) has the correct precision according to the .NET DateTime class and fixes the problem.

+4
source

Source: https://habr.com/ru/post/1781390/


All Articles