HQL with the full class name

Say I have a Foo entity -

package com.some.company.model;
// imports
@Entity
public class Foo{
    @Id
    private Long id;    

    // getters / setters and other properties omitted   
}

so when working with Entity through HQL, I prefer to reference Entity using the fully qualified class name, for example -

entityManager.createQuery(String.format("delete from %s where id = :id", Foo.class.getName()))
                .setParameter("id", fooId)
                .executeUpdate();

I noticed one thing in the annotation @Entity- by default, the name property has an unqualified name for the entity class. what makes me think why an unconditional name?
What should I use in an unqualified HQL name or fully qualified name?

+3
source share
2 answers

It makes no sense to use the full name because Hibernate will not allow duplicate entity names. Therefore, if you had different objects with the same name in different packages. Hibernate will throw a DuplicateMappingException.

+4

, , ... , , HQL . , , , 2 Foo (, ), (, AFoo, BFoo), , .

0

All Articles