NHibernate<时间戳>Oracle 数据库的映射导致 StaleStateException

发布于 2024-10-09 00:29:09 字数 654 浏览 0 评论 0原文

我们有一个 NHibernate 应用程序,正在从 SQL Server 迁移到 Oracle。我们的乐观并发是通过 映射元素实现的。

Oracle中对应的Version列的数据类型是DATE。保存对象后,内存中的 C# 对象会留下以毫秒为单位的时间戳值(例如 12:34:56.789),而数据库中的值仅精确到秒(例如 12:34:56)。因此,如果我们尝试第二次保存该对象,我们会收到 StaleStateException,因为两个值不匹配。

我尝试通过将 Version 列的数据类型更改为 TIMESTAMP(3) 来解决此问题。不幸的是,C# 对象和 DB 值仍然相差一毫秒(例如 12:34:56.789 与 12:34:56.788),因此第二次尝试保存对象仍然会导致 StaleStateException。

我可以做什么来创建一个工作 映射到 DATETIMESTAMP 类型的 Oracle 列,以便可以使用相同的对象保存多次?

谢谢。

——布莱恩

We have an NHibernate app that we are migrating from SQL Server to Oracle. Our optimistic concurrency is implemented via a <timestamp name="Version"> mapping element.

The data type of the corresponding Version column in Oracle is DATE. After we save an object, the in-memory C# object is left with a timestamp value in milliseconds (e.g. 12:34:56.789) while the value in the database is precise only to the second (e.g. 12:34:56). Thus, if we attempt to save the object a 2nd time, we get a StaleStateException because the two values do not match.

I attempted to fix this by altering the data type of the Version column to TIMESTAMP(3). Unfortunately, the C# object and the DB value are still off by one millisecond (e.g. 12:34:56.789 vs 12:34:56.788), so the 2nd attempt to save the object still causes a StaleStateException.

What can I do to create a working <timestamp> mapping to an Oracle column of type DATE or TIMESTAMP so that the same object can be saved multiple times?

Thanks.

-- Brian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

计㈡愣 2024-10-16 00:29:09

TIMESTAMP(7) 具有与 .NET DateTime 类匹配的正确精度并解决了问题。

TIMESTAMP(7) has the correct precision to match the .NET DateTime class and fixed the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文