NHibernate - 当 PK 列之一为 NULL 时,使用复合 PK 删除对象

发布于 2024-08-13 09:44:22 字数 744 浏览 4 评论 0原文

嘿,我正在尝试从 Oracle 10g 表中删除以下结构的实体:

class Record 
{
   string id;
   string name;
   DateTime dateTime;
}

使用以下映射:

<class name="Records" table="RECS">
   <composite-id>
      <key-property name="P_ID" />
      <key-property name="NAME" />
   </id>
   <property name="dateTime" column="DATE_TIME_V" />
</class>

现在,假设表的 PK 是 P_ID 和 NAME 列(复合键),当 NAME 允许空值但 P_ID 不允许时t。 现在的问题是,当 NHibernate 尝试删除一个对象(比如 P_ID = 9 且 NAME = NULL)时,它会输出以下删除语句:

delete from RECS R where R.P_ID = 9 and NAME = NULL

显然,该操作不会删除任何内容,因为 'NAME = NULL' 应该是 'NAME IS无效的'。 我是否在这里遗漏了一些导致 NHibernate 像对待任何其他值一样对待空值的东西?

谢谢, 哈雷尔

Hey, i'm trying to delete an entity of the following structure from an Oracle 10g tables:

class Record 
{
   string id;
   string name;
   DateTime dateTime;
}

with the following mapping:

<class name="Records" table="RECS">
   <composite-id>
      <key-property name="P_ID" />
      <key-property name="NAME" />
   </id>
   <property name="dateTime" column="DATE_TIME_V" />
</class>

Now, say that the table's PK is P_ID and NAME columns (composite key), when NAME allow nulls but P_ID doesn't.
Now, the issue is that when NHibernate tries to delete an object with, say, P_ID = 9 and NAME = NULL, it outputs the following delete statement:

delete from RECS R where R.P_ID = 9 and NAME = NULL

Obvioisly, the operation will delete nothing since 'NAME = NULL' should be 'NAME IS NULL'.
Am i'm missing something here that causes NHibernate to treat nulls like any other values?

Thanks,
Harel

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

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

发布评论

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

评论(1

迷鸟归林 2024-08-20 09:44:22

“假设表的 PK 是 P_ID 并且
NAME 列(复合键),当
NAME 允许空值”

不可能。主键列不能为空。您拥有的是一个没有主键的表,这就是您遇到问题的原因。

"say that the table's PK is P_ID and
NAME columns (composite key), when
NAME allow nulls"

Not possible. A primary key column cannot be null. What you have is a table WITHOUT a primary key, which is why you are getting problems.

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