NHibernate - 当 PK 列之一为 NULL 时,使用复合 PK 删除对象
嘿,我正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可能。主键列不能为空。您拥有的是一个没有主键的表,这就是您遇到问题的原因。
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.