强制 EclipseLink 在删除语句中使用鉴别器列
我正在使用 JPA/EclipseLink。我定义了一个名为 Parameter 的超类
@Entity
@Table(name="parameter")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type",discriminatorType=DiscriminatorType.STRING,length=64)
@DiscriminatorValue(value="fr.itce.babel.entity.Parameter")
public class Parameter {
@Id
String code;
String value;
...
}
,另外两个实体继承
@Entity
@DiscriminatorValue(value="fr.itce.babel.entity.Line")
public class Line extends Parameter {
}
@Entity
@DiscriminatorValue(value="fr.itce.babel.entity.Phase")
public class Phase extends Parameter {
}
当我选择所有“Line”时,生成的查询类型
select code, value from parameter where type = ?
为 type = 'fr.itce.babel.entity.Line'
它对我有用。
但是,当删除一个 Line 实体时,我得到类似这样的东西:
delete from parameter where code = ?
Yuck...它不使用鉴别器列,因此如果它是一个 Phase,则删除具有相同代码事件的所有实体...
我怎样才能强制使用我的删除查询中的鉴别器列?
I'm using JPA/EclipseLink. I defined a superclass named Parameter
@Entity
@Table(name="parameter")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type",discriminatorType=DiscriminatorType.STRING,length=64)
@DiscriminatorValue(value="fr.itce.babel.entity.Parameter")
public class Parameter {
@Id
String code;
String value;
...
}
And two other entities inheriting
@Entity
@DiscriminatorValue(value="fr.itce.babel.entity.Line")
public class Line extends Parameter {
}
@Entity
@DiscriminatorValue(value="fr.itce.babel.entity.Phase")
public class Phase extends Parameter {
}
When I'm selecting all "Line", the query generated is
select code, value from parameter where type = ?
with type = 'fr.itce.babel.entity.Line'
It works for me.
But when deleting a Line entity, I get something like this
delete from parameter where code = ?
Yuck... it doesn't use the discriminator column and so delete all entities with the same code event if it is a Phase...
How can I force the use of the discriminator column in my delete query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些实体位于一个表中,其中键列是代码。因为它是一个键,所以它是唯一的,并且不可能有多个实体具有相同的代码值。 EclipseLink 知道实体的类型,因此删除语句中不需要有鉴别器。
These entities are in one table where key column is code. Because it is a key, it is unique and there is no possibility to have more than one entity with same value of code. EclipseLink is aware about type of Entity so there is no need to have discriminator in delete statement.
code是Id,并且是唯一的,所以应该没有问题吧?
您可以使用 DescriptorQueryManager 上的自定义 deleteQuery 和 DescriptorCustomizer 强制包含该类型,但我看不到这样做的原因,因为代码是 Id。如果您担心用户删除不正确的对象,您可能还希望使用乐观锁定(@Version)。
code is the Id, and unique, so there should not be an issue?
You could force the type to be included using a custom deleteQuery on the DescriptorQueryManager, using a DescriptorCustomizer, but I can't see I reason for this as code is the Id. You may also wish to use optimistic locking (@Version) if you are concerned of users deleting the incorrect object.