假设我有一个名为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 中应该使用非限定名称还是完全限定名称呢?