Package org.hibernate

Interface EntityNameResolver

  • All Known Implementing Classes:
    CoordinatingEntityNameResolver
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface EntityNameResolver
    An object capable of determining the entity name for a given entity instance.

    A single Java class may be mapped as an entity multiple times, with each mapping distinguished by a distinct entity name. This is not currently possible using annotations, but it may be achieved using XML-based mappings. If a class is mapped multiple times, Hibernate needs a way to determine which entity is represented by a given instance of the class. There are two ways to provide this information:

    • by passing the entity name explicitly to methods of Session, for example, by calling Session.persist(String, Object), but this can be verbose and lacking in typesafety, or
    • by having the entity instance itself carry around the information, for example, by giving it a field holding the entity name, and supplying an EntityNameResolver which is capable of extracting the information from the entity instance.
    See Also:
    SessionFactoryBuilder.addEntityNameResolver(EntityNameResolver...), Configuration.addEntityNameResolver(EntityNameResolver)
    • Method Detail

      • resolveEntityName

        String resolveEntityName​(Object entity)
        Given an entity instance, determine its entity name.
        Parameters:
        entity - The entity instance.
        Returns:
        The corresponding entity name, or null if this implementation does not know how to perform resolution for the given entity instance.