Let's say I have entity Foo like -
package com.some.company.model;
// imports
@Entity
public class Foo{
@Id
private Long id;
// getters / setters and other properties omitted
}
so while dealing with Entity through HQL I prefer to refer the Entity by fully qualified class name like -
entityManager.createQuery(String.format("delete from %s where id = :id", Foo.class.getName()))
.setParameter("id", fooId)
.executeUpdate();
I noticed one thing in @Entity
annotation - the name property has a unqualified name of the entity class by default. which makes me think why unqualified name?
Which should I use in HQL unqualified name or fully qualified name?
There is no point to use the fully qualified name because Hibernate won't allow duplicate entity names. So if you had different entities with the same name, in different packages. Hibernate will throw a DuplicateMappingException.