Class HibernateColumnResolverUtility
java.lang.Object
com.broadleafcommerce.data.tracking.jpa.support.HibernateColumnResolverUtility
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents the physical location of a field in the database.static classRepresents the physical location of primary key information for an entity. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetPhysicalColumnLocationForPrimaryKey(@NonNull jakarta.persistence.EntityManager entityManager, @NonNull Class<?> entityClass) Resolve the physical location of the primary key column.getPhysicalColumnLocationForSimpleField(@NonNull jakarta.persistence.EntityManager entityManager, @NonNull Class<?> entityClass, @NonNull String propertyPath) Resolves a dot-separated property path to a physical table and column.
-
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
@Embeddedinside@Embeddedby traversing theModelParthierarchy. - 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.
- Ignores Associations: Returns
-
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.
-