liveBook · Manning

Entity name

As explained in Java Persistence with Spring Data and Hibernate epub

An entity name is the query-language name by which a persistent entity class is referenced in JPA queries.

An entity name is the query-language name used to reference a persistent entity class in JPA queries. JPA imports entity names automatically, so queries can usually use a class’s short name without its package. section 5.3.1

Choose a name that keeps query references unambiguous:

  • Use the default short class name when the persistence unit contains no conflicting entity classes. section 5.3.1
  • Assign an explicit JPA entity name when classes with the same short name exist in different packages. section 5.3.1
  • Use a fully qualified name in queries when retaining the default entity names is preferable. section 5.3.1

Resolving an entity-name collision

Annotate the conflicting class with @Entity(name = "AuctionItem"), then reference it as select i from AuctionItem i rather than Item. section 5.3.1

package my.other.model;
@javax.persistence.Entity(name = "AuctionItem")
public class Item {
    //  . . .
 
}

Shows the annotation that assigns AuctionItem as the query-language name for the Item class. section 5.3.1

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains default imports, package-name collisions, explicit renaming, and fully qualified alternatives, but not query-engine internals.
Examples
Uses duplicate Item classes, AuctionItem, and select i from AuctionItem i.
What it assumes
Assumes persistent entity classes and basic JPA query strings while distinguishing query names from package-qualified class names.
What you can do after
Evaluate and choose unambiguous entity names for JPA query strings.
How it connects
Connects entity classes, JPA queries, package names, and naming strategies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.