Class HibernateColumnResolverUtility

java.lang.Object
com.broadleafcommerce.data.tracking.jpa.support.HibernateColumnResolverUtility

public class HibernateColumnResolverUtility extends Object
Stateless utility to resolve logical JPA property paths (e.g., "address.city") to physical database locations (Table Name + Column Name).

This utility interacts directly with Hibernate 6's EntityMappingType metamodel to bridge the gap between object-oriented property paths and relational schema definitions, primarily for generating Native SQL.

  • Constructor Details

    • HibernateColumnResolverUtility

      public HibernateColumnResolverUtility()
  • Method Details

    • getPhysicalColumnLocationForSimpleField

      public static Optional<HibernateColumnResolverUtility.ColumnLocation> getPhysicalColumnLocationForSimpleField(@NonNull @NonNull jakarta.persistence.EntityManager entityManager, @NonNull @NonNull Class<?> entityClass, @NonNull @NonNull String propertyPath)
      Resolves a dot-separated property path to a physical table and column.

      Key Behaviors & Limitations:

      • Ignores Associations: Returns Optional.empty() for @OneToMany, @ManyToOne, or any collection types.
      • Ignores Formulas: Returns Optional.empty() if the property maps to a SQL formula instead of a physical column.
      • Deep Nesting Support: Handles @Embedded inside @Embedded by traversing the ModelPart hierarchy.
      • JOINED Inheritance Support: Identifies the specific table (Parent vs. Child) where a property resides.
      Parameters:
      entityManager - The active EntityManager.
      entityClass - The JPA Entity class (can be the subclass in a JOINED hierarchy).
      propertyPath - The path to the property (e.g., "name" or "audit.createdDate").
      Returns:
      Optional containing the location, or empty if path is invalid, refers to an association, or maps to multiple columns/formulas.
    • getPhysicalColumnLocationForPrimaryKey

      public static Optional<HibernateColumnResolverUtility.PrimaryKeyColumnLocation> getPhysicalColumnLocationForPrimaryKey(@NonNull @NonNull jakarta.persistence.EntityManager entityManager, @NonNull @NonNull Class<?> entityClass)
      Resolve the physical location of the primary key column. Only supports simple single-column primary keys.
      Parameters:
      entityManager - The active EntityManager.
      entityClass - The JPA Entity class (can be the subclass in a JOINED hierarchy).
      Returns:
      Optional containing the primary key location, or empty if path is invalid, refers to an association, or maps to multiple columns/formulas.