假设我有像这样的实体 Foo -
package com.some.company.model;
// imports
@Entity
public class Foo{
@Id
private Long id;
// getters / setters and other properties omitted
}
因此,在通过 HQL 处理实体时,我更喜欢通过完全限定的类名来引用实体,例如 -
entityManager.createQuery(String.format("delete from %s where id = :id", Foo.class.getName()))
.setParameter("id", fooId)
.executeUpdate();
我注意到 @Entity
注释中的一件事 - 默认情况下,name 属性具有实体类的非限定名称。这让我觉得为什么不合格的名字?
我应该在 HQL 非限定名称或完全限定名称中使用哪个?
最佳答案
没有必要使用完全限定名称,因为 Hibernate 不允许重复的实体名称。因此,如果您在不同的包中有具有相同名称的不同实体。 Hibernate 将抛出 DuplicateMappingException。
关于java - 具有完全限定类名的 HQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5327682/