Top Fields Constructors Methods
org.hibernate.boot.model.internal

public Class BinderHelper

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, .Repeatable, java.lang.reflect.Method, java.util.ArrayList, .Arrays, .EnumSet, .HashMap, .Iterator, .LinkedHashSet, .List, .Map, .Set, .StringTokenizer, java.util.function.Consumer, java.util.stream.Stream, org.hibernate.AnnotationException, .AssertionFailure, .FetchMode, .MappingException, org.hibernate.annotations.AnyDiscriminatorValue, .AnyDiscriminatorValues, .Cascade, .CascadeType, .DialectOverride, .Formula, .OnDeleteAction, .SqlFragmentAlias, org.hibernate.annotations.common.reflection.XAnnotatedElement, .XClass, .XPackage, .XProperty, org.hibernate.boot.registry.classloading.spi.ClassLoaderService, org.hibernate.boot.spi.InFlightMetadataCollector, .MetadataBuildingContext, .PropertyData, org.hibernate.dialect.DatabaseVersion, .Dialect, org.hibernate.internal.util.StringHelper, org.hibernate.mapping.Any, .AttributeContainer, .BasicValue, .Collection, .Column, .Component, .Join, .MappedSuperclass, .PersistentClass, .Property, .Selectable, .SyntheticProperty, .Table, .ToOne, .Value, org.hibernate.type.descriptor.java.JavaType, jakarta.persistence.ConstraintMode, .Embeddable, .EmbeddedId, .FetchType, .ForeignKey, .ManyToOne, .OneToOne

Author
Emmanuel Bernard

Field Summary

Modifier and TypeField and Description
public static final Set<String>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static String
public static Any
buildAnyValue(Column discriminatorColumn, Formula discriminatorFormula, AnnotatedJoinColumns keyColumns, PropertyData inferredData, OnDeleteAction onDeleteAction, boolean lazy, Nullability nullability, PropertyHolder propertyHolder, EntityBinder entityBinder, boolean optional, MetadataBuildingContext context)

private static void
checkColumnInSameTable(AnnotatedJoinColumns joinColumns, PersistentClass targetEntity, PersistentClass associatedEntity, MetadataBuildingContext context, Object columnOwner)

All the referenced columns must belong to the same table, that is findColumnOwner(PersistentClass, String, MetadataBuildingContext) must return the same value for all of them.

public static void
checkMappedByType(String mappedBy, Value targetValue, String propertyName, PropertyHolder propertyHolder, Map<String, PersistentClass> persistentClasses)

private static boolean
private static Property
cloneProperty(PersistentClass ownerEntity, MetadataBuildingContext context, Property property)

Create a (deep) copy of the Property, by also recursively cloning any child Component instances, but reusing other kinds of Value and other attributes.

private static CascadeType
private static EnumSet<CascadeType>
public static void
createSyntheticPropertyReference(AnnotatedJoinColumns joinColumns, PersistentClass targetEntity, PersistentClass associatedEntity, Value value, String propertyName, boolean inverse, MetadataBuildingContext context)

Here we address a fundamental problem: the @JoinColumn annotation specifies the referenced column in the target table via referencedColumnName, but Hibernate needs to know which property or field of the target entity class holds the value of the referenced column at the Java level.

public static <A extends Annotation> A

Returns:

The annotation or null
extractFromPackage
(Class<A>
The type of annotation to return
annotationType
,
XClass
The class in the package
xClass
,
MetadataBuildingContext
The processing context
context
)

Extract an annotation from the package-info for the package the given class is defined in

public static AttributeContainer
findColumnOwner(PersistentClass persistentClass, String columnName, MetadataBuildingContext context)

Find the column owner (ie PersistentClass or Join) of columnName.

private static List<Property>
public static Property
findPropertyByName(PersistentClass associatedClass, String propertyName)

Retrieve the property by path in a recursive way, including IdentifierProperty in the loop If propertyName is null or empty, the IdentifierProperty is returned

public static Property
findPropertyByName(Component component, String propertyName)

Retrieve the property by path in a recursive way

public static AttributeContainer
public static String
getCascadeStrategy(CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation, boolean orphanRemoval, boolean forcePersist)

public static FetchMode
public static MappedSuperclass
getMappedSuperclassOrNull(XClass declaringClass, Map<XClass, InheritanceState> inheritanceStatePerClass, MetadataBuildingContext context)

public static <T extends Annotation> T
public static String
pack-priv static PropertyData
getPropertyOverriddenByMapperOrMapsId(boolean isId, PropertyHolder propertyHolder, String propertyName, MetadataBuildingContext buildingContext)

public static String
getRelativePath(PropertyHolder propertyHolder, String propertyName)

public static boolean
pack-priv static boolean
isCompositeId(XClass entityClass, XProperty idProperty)

public static boolean
pack-priv static boolean
public static boolean
isPrimitive(String elementTypeName)

private static Property
makeSyntheticComponentProperty(PersistentClass ownerEntity, AttributeContainer persistentClassOrJoin, MetadataBuildingContext context, String syntheticPropertyName, List<Property> properties)

Build the "synthetic" Component that holds all the properties referenced by a foreign key mapping specified as a list of jakarta.persistence.JoinColumn annotations with explicit referencedColumnName()s.

private static void
matchColumnsByProperty(Property property, Map<Column, Set<Property>> columnsToProperty)

public static boolean
noConstraint(ForeignKey foreignKey, boolean noConstraintByDefault)

private static void
private static Property
referencedProperty(PersistentClass ownerEntity, PersistentClass associatedEntity, String propertyName, boolean inverse, AttributeContainer columnOwner, List<Property> properties, MetadataBuildingContext context)

If the referenced columns correspond to exactly one property of the primary table of the exact target entity subclass, just use that property.

private static void
registerSyntheticProperty(PersistentClass ownerEntity, Value value, boolean inverse, PersistentClass associatedClass, String propertyName, String syntheticPropertyName, MetadataBuildingContext context)

private static String
public static Property
shallowCopy(Property property)

Create a copy of the Property, reusing the same Value and other attributes.

private static String
syntheticPropertyName(String propertyName, boolean inverse, PersistentClass associatedClass)

public static Map<String, String>
public static Map<String, String>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PRIMITIVE_NAMESback to summary
public static final Set<String> PRIMITIVE_NAMES

Constructor Detail

BinderHelperback to summary
private BinderHelper()

Method Detail

associationMessageback to summary
private static String associationMessage(PersistentClass associatedEntity, AnnotatedJoinColumns joinColumns)
buildAnyValueback to summary
public static Any buildAnyValue(Column discriminatorColumn, Formula discriminatorFormula, AnnotatedJoinColumns keyColumns, PropertyData inferredData, OnDeleteAction onDeleteAction, boolean lazy, Nullability nullability, PropertyHolder propertyHolder, EntityBinder entityBinder, boolean optional, MetadataBuildingContext context)
checkColumnInSameTableback to summary
private static void checkColumnInSameTable(AnnotatedJoinColumns joinColumns, PersistentClass targetEntity, PersistentClass associatedEntity, MetadataBuildingContext context, Object columnOwner)

All the referenced columns must belong to the same table, that is findColumnOwner(PersistentClass, String, MetadataBuildingContext) must return the same value for all of them.

checkMappedByTypeback to summary
public static void checkMappedByType(String mappedBy, Value targetValue, String propertyName, PropertyHolder propertyHolder, Map<String, PersistentClass> persistentClasses)
checkReferencedClassback to summary
private static boolean checkReferencedClass(PersistentClass ownerClass, PersistentClass referencedClass)
clonePropertyback to summary
private static Property cloneProperty(PersistentClass ownerEntity, MetadataBuildingContext context, Property property)

Create a (deep) copy of the Property, by also recursively cloning any child Component instances, but reusing other kinds of Value and other attributes.

convertCascadeTypeback to summary
private static CascadeType convertCascadeType(CascadeType cascade)
convertToHibernateCascadeTypeback to summary
private static EnumSet<CascadeType> convertToHibernateCascadeType(CascadeType[] ejbCascades)
createSyntheticPropertyReferenceback to summary
public static void createSyntheticPropertyReference(AnnotatedJoinColumns joinColumns, PersistentClass targetEntity, PersistentClass associatedEntity, Value value, String propertyName, boolean inverse, MetadataBuildingContext context)

Here we address a fundamental problem: the @JoinColumn annotation specifies the referenced column in the target table via referencedColumnName, but Hibernate needs to know which property or field of the target entity class holds the value of the referenced column at the Java level. (It's going to need the value when it writes the association.)

Complicating this hugely is the fact that an association might be based on a composite key with multiple @JoinColumns, and so the referenced columns might even be spread out over multiple fields or properties of the target entity. There's even some extra minor complications resulting from multi-table inheritance and secondary tables.

The solution here is:

  • if the referenced columns correspond to exactly one property of the target entity, we're good, just use it, or
  • otherwise, if a composite key is spread out over multiple properties, then create a "synthetic" Component in the model that aggregates these properties and is considered the target of the association.

Certain limitations arise from the way this solution is currently implemented: for example, if a referenced column belongs to a property of an @Embeddable, then every column of that embeddable must occur in the list of referenced columns, and the order of the columns must line up! Some of these limitations could be relaxed by writing a better algorithm for building the synthetic Component.

extractFromPackageback to summary
public static <A extends Annotation> A extractFromPackage(Class<A> annotationType, XClass xClass, MetadataBuildingContext context)

Extract an annotation from the package-info for the package the given class is defined in

Parameters
annotationType:Class<A>

The type of annotation to return

xClass:XClass

The class in the package

context:MetadataBuildingContext

The processing context

Returns:A

The annotation or null

findColumnOwnerback to summary
public static AttributeContainer findColumnOwner(PersistentClass persistentClass, String columnName, MetadataBuildingContext context)

Find the column owner (ie PersistentClass or Join) of columnName. If columnName is null or empty, persistentClass is returned

findPropertiesByColumnsback to summary
private static List<Property> findPropertiesByColumns(Object columnOwner, AnnotatedJoinColumns columns, PersistentClass associatedEntity, MetadataBuildingContext context)
findPropertyByNameback to summary
public static Property findPropertyByName(PersistentClass associatedClass, String propertyName)

Retrieve the property by path in a recursive way, including IdentifierProperty in the loop If propertyName is null or empty, the IdentifierProperty is returned

findPropertyByNameback to summary
public static Property findPropertyByName(Component component, String propertyName)

Retrieve the property by path in a recursive way

findReferencedColumnOwnerback to summary
public static AttributeContainer findReferencedColumnOwner(PersistentClass persistentClass, AnnotatedJoinColumn joinColumn, MetadataBuildingContext context)
getCascadeStrategyback to summary
public static String getCascadeStrategy(CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation, boolean orphanRemoval, boolean forcePersist)
getFetchModeback to summary
public static FetchMode getFetchMode(FetchType fetch)
getMappedSuperclassOrNullback to summary
public static MappedSuperclass getMappedSuperclassOrNull(XClass declaringClass, Map<XClass, InheritanceState> inheritanceStatePerClass, MetadataBuildingContext context)
getOverridableAnnotationback to summary
public static <T extends Annotation> T getOverridableAnnotation(XAnnotatedElement element, Class<T> annotationType, MetadataBuildingContext context)
getPathback to summary
public static String getPath(PropertyHolder holder, PropertyData property)
getPropertyOverriddenByMapperOrMapsIdback to summary
pack-priv static PropertyData getPropertyOverriddenByMapperOrMapsId(boolean isId, PropertyHolder propertyHolder, String propertyName, MetadataBuildingContext buildingContext)
getRelativePathback to summary
public static String getRelativePath(PropertyHolder propertyHolder, String propertyName)
hasToOneAnnotationback to summary
public static boolean hasToOneAnnotation(XAnnotatedElement property)
isCompositeIdback to summary
pack-priv static boolean isCompositeId(XClass entityClass, XProperty idProperty)
isDefaultback to summary
public static boolean isDefault(XClass clazz, MetadataBuildingContext context)
isGlobalGeneratorNameGlobalback to summary
pack-priv static boolean isGlobalGeneratorNameGlobal(MetadataBuildingContext context)
isPrimitiveback to summary
public static boolean isPrimitive(String elementTypeName)
makeSyntheticComponentPropertyback to summary
private static Property makeSyntheticComponentProperty(PersistentClass ownerEntity, AttributeContainer persistentClassOrJoin, MetadataBuildingContext context, String syntheticPropertyName, List<Property> properties)

Build the "synthetic" Component that holds all the properties referenced by a foreign key mapping specified as a list of jakarta.persistence.JoinColumn annotations with explicit referencedColumnName()s.

matchColumnsByPropertyback to summary
private static void matchColumnsByProperty(Property property, Map<Column, Set<Property>> columnsToProperty)
noConstraintback to summary
public static boolean noConstraint(ForeignKey foreignKey, boolean noConstraintByDefault)
processAnyDiscriminatorValuesback to summary
private static void processAnyDiscriminatorValues(XProperty property, Consumer<AnyDiscriminatorValue> consumer)
referencedPropertyback to summary
private static Property referencedProperty(PersistentClass ownerEntity, PersistentClass associatedEntity, String propertyName, boolean inverse, AttributeContainer columnOwner, List<Property> properties, MetadataBuildingContext context)

If the referenced columns correspond to exactly one property of the primary table of the exact target entity subclass, just use that property. Otherwise, if a composite key is spread out over multiple properties, then create a "synthetic" Component that aggregates these properties and is considered the target of the association. This method adds the property holding the synthetic component to the target entity PersistentClass by side effect.

registerSyntheticPropertyback to summary
private static void registerSyntheticProperty(PersistentClass ownerEntity, Value value, boolean inverse, PersistentClass associatedClass, String propertyName, String syntheticPropertyName, MetadataBuildingContext context)
renderCascadeTypeListback to summary
private static String renderCascadeTypeList(EnumSet<CascadeType> cascadeTypes)
shallowCopyback to summary
public static Property shallowCopy(Property property)

Create a copy of the Property, reusing the same Value and other attributes.

syntheticPropertyNameback to summary
private static String syntheticPropertyName(String propertyName, boolean inverse, PersistentClass associatedClass)
toAliasEntityMapback to summary
public static Map<String, String> toAliasEntityMap(SqlFragmentAlias[] aliases)
toAliasTableMapback to summary
public static Map<String, String> toAliasTableMap(SqlFragmentAlias[] aliases)