Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ public <T> QueryImplementor<T> createQuery(CriteriaQuery<T> criteriaQuery) {
return createCriteriaQuery( selectStatement, criteriaQuery.getResultType() );
}
catch (RuntimeException e) {
if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
if ( getSessionFactory().getSessionFactoryOptions().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
markForRollbackOnly();
}
throw getExceptionConverter().convert( e );
Expand All @@ -1483,7 +1483,7 @@ public QueryImplementor<?> createQuery(@SuppressWarnings("rawtypes") CriteriaUpd
return createCriteriaQuery( (SqmUpdateStatement<?>) criteriaUpdate, null );
}
catch (RuntimeException e) {
if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
if ( getSessionFactory().getSessionFactoryOptions().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
markForRollbackOnly();
}
throw getExceptionConverter().convert( e );
Expand All @@ -1497,7 +1497,7 @@ public QueryImplementor<?> createQuery(@SuppressWarnings("rawtypes") CriteriaDel
return createCriteriaQuery( (SqmDeleteStatement<?>) criteriaDelete, null );
}
catch (RuntimeException e) {
if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
if ( getSessionFactory().getSessionFactoryOptions().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
markForRollbackOnly();
}
throw getExceptionConverter().convert( e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ public <T> QueryImplementor<T> createQuery(CriteriaSelect<T> selectQuery) {
return createCriteriaQuery( selectStatement, selectStatement.getResultType() );
}
catch (RuntimeException e) {
if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
if ( getSessionFactory().getSessionFactoryOptions().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
markForRollbackOnly();
}
throw getExceptionConverter().convert( e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ else if ( unresolvedIds.size() == ids.length ) {
protected abstract Object[] toIdArray(List<Object> ids);

private boolean isIdCoercionEnabled() {
return !getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled();
return !getSessionFactory().getSessionFactoryOptions().getJpaCompliance().isLoadByIdComplianceEnabled();
}

public interface ResolutionConsumer<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static <K> K[] normalizeKeys(
}

final K[] typedArray = createTypedArray( keyClass, keys.length );
final boolean coerce = !sessionFactory.getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled();
final boolean coerce = !sessionFactory.getSessionFactoryOptions().getJpaCompliance().isLoadByIdComplianceEnabled();
if ( !coerce ) {
System.arraycopy( keys, 0, typedArray, 0, keys.length );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import org.hibernate.Incubating;
import org.hibernate.Internal;
import org.hibernate.graph.RootGraph;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.MappingModelExpressible;
import org.hibernate.type.BindableType;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.persister.collection.CollectionPersister;
Expand All @@ -30,6 +28,8 @@
/**
* Access to information about the runtime relational O/R mapping model.
*
* @apiNote This is an incubating SPI. Its name and package may change.
*
* @author Steve Ebersole
*/
@Incubating
Expand All @@ -39,23 +39,6 @@ public interface MappingMetamodel extends Metamodel {
*/
TypeConfiguration getTypeConfiguration();

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SQM model -> Mapping model

// todo (6.0) : POC intended for use in SQM to SQL translation
@Internal
MappingModelExpressible<?> resolveMappingExpressible(
SqmExpressible<?> sqmExpressible,
Function<NavigablePath,
TableGroup> tableGroupLocator);

/**
* Given a Java type, determine the corresponding BindableType to
* use implicitly
*/
<T> BindableType<T> resolveQueryParameterType(Class<T> javaType);


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Entity descriptors

Expand Down Expand Up @@ -186,7 +169,7 @@ MappingModelExpressible<?> resolveMappingExpressible(
// JPA entity graphs

RootGraph<?> findNamedGraph(String name);
<T> void addNamedEntityGraph(String graphName, RootGraphImplementor<T> entityGraph);
void addNamedEntityGraph(String graphName, RootGraph<?> entityGraph);
void forEachNamedGraph(Consumer<RootGraph<?>> action);
RootGraph<?> defaultGraph(String entityName);
RootGraph<?> defaultGraph(Class<?> entityJavaType);
Expand All @@ -196,4 +179,14 @@ MappingModelExpressible<?> resolveMappingExpressible(
List<RootGraph<?>> findRootGraphsForType(Class<?> baseEntityJavaType);
List<RootGraph<?>> findRootGraphsForType(String baseEntityName);
List<RootGraph<?>> findRootGraphsForType(EntityPersister baseEntityDescriptor);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SQM model -> Mapping model

// TODO Layer breaker used in SQM to SQL translation.
// Consider moving to QueryEngine or collaborators.
@Internal
MappingModelExpressible<?> resolveMappingExpressible(
SqmExpressible<?> sqmExpressible,
Function<NavigablePath, TableGroup> tableGroupLocator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ else if ( incoming instanceof Object[] values ) {
}

private boolean isLoadByIdComplianceEnabled() {
return getTypeConfiguration().getJpaCompliance().isLoadByIdComplianceEnabled();
return sessionFactory.getSessionFactoryOptions().getJpaCompliance().isLoadByIdComplianceEnabled();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@
import java.util.Set;

import jakarta.persistence.EntityGraph;
import jakarta.persistence.metamodel.EmbeddableType;
import jakarta.persistence.metamodel.EntityType;
import jakarta.persistence.metamodel.ManagedType;

import jakarta.persistence.metamodel.Metamodel;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.Incubating;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.jpa.spi.JpaCompliance;
import org.hibernate.graph.RootGraph;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.java.EnumJavaType;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.spi.TypeConfiguration;

/**
* Extensions to the JPA-defined {@linkplain Metamodel metamodel} of
* persistent Java types.
*
* @apiNote This is an incubating API. Its name and package may change.
*
* @see MappingMetamodel
*
* @since 6.0
Expand All @@ -36,17 +32,6 @@
@Incubating
public interface JpaMetamodel extends Metamodel {

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Context

/**
* todo (6.0) : should we expose JpaMetamodel from TypeConfiguration?
*/
TypeConfiguration getTypeConfiguration();

ServiceRegistry getServiceRegistry();


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Extended features

Expand Down Expand Up @@ -139,24 +124,13 @@ public interface JpaMetamodel extends Metamodel {


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JPA defined bulk accessors
// Entity graphs

@Override
Set<ManagedType<?>> getManagedTypes();

@Override
Set<EntityType<?>> getEntities();
void addNamedEntityGraph(String graphName, RootGraph<?> entityGraph);

@Override
Set<EmbeddableType<?>> getEmbeddables();
RootGraph<?> findEntityGraphByName(String name);

<T> void addNamedEntityGraph(String graphName, RootGraphImplementor<T> entityGraph);

<T> RootGraphImplementor<T> findEntityGraphByName(String name);

<T> List<RootGraphImplementor<? super T>> findEntityGraphsByJavaType(Class<T> entityClass);
<T> List<RootGraph<? super T>> findEntityGraphsByJavaType(Class<T> entityClass);

<T> Map<String, EntityGraph<? extends T>> getNamedEntityGraphs(Class<T> entityType);

JpaCompliance getJpaCompliance();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.Serializable;

import org.hibernate.Incubating;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.spi.DotIdentifierSequence;
import org.hibernate.spi.NavigablePath;
Expand All @@ -14,17 +15,18 @@
* A compound path which represents a {@link org.hibernate.metamodel.mapping.ModelPart}
* and uniquely identifies it with the runtime metamodel.
* <p/>
* The {@linkplain #isRoot() root} will name either an
* The {@linkplain #isRoot root} will name either an
* {@linkplain org.hibernate.metamodel.MappingMetamodel#getEntityDescriptor entity} or
* {@linkplain org.hibernate.metamodel.MappingMetamodel#getCollectionDescriptor collection}
* {@linkplain org.hibernate.metamodel.MappingMetamodel#getCollectionDescriptor collection}.
*
*
* @apiNote Poorly named. Should probably have been `org.hibernate.metamodel.model.mapping.MappingRole`;
* @apiNote This is an incubating SPI type, and will move to {@link org.hibernate.spi}.
* It might be renamed to {@code org.hibernate.metamodel.model.mapping.MappingRole};
* the term "navigable" here is meant to indicate that we could navigate to the specific
* {@link org.hibernate.metamodel.mapping.ModelPart} given the role.
*
* @author Steve Ebersole
*/
@Incubating
public final class NavigableRole implements DotIdentifierSequence, Serializable {
public static final String IDENTIFIER_MAPPER_PROPERTY = NavigablePath.IDENTIFIER_MAPPER_PROPERTY;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.graph.RootGraph;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.spi.JpaCompliance;
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.MappingMetamodel;
Expand Down Expand Up @@ -111,21 +111,14 @@ public JpaMetamodelImpl(
this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
}

@Override
public TypeConfiguration getTypeConfiguration() {
return typeConfiguration;
}

@Override
public ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}

@Override
public JpaCompliance getJpaCompliance() {
return typeConfiguration.getJpaCompliance();
}

@Override
public @Nullable <X> ManagedDomainType<X> findManagedType(@Nullable String typeName) {
//noinspection unchecked
Expand Down Expand Up @@ -394,31 +387,31 @@ private Field getJavaField(String className, String fieldName) throws NoSuchFiel
}

@Override
public <T> void addNamedEntityGraph(String graphName, RootGraphImplementor<T> entityGraph) {
final EntityGraph<?> old = entityGraphMap.put( graphName, entityGraph.makeImmutableCopy( graphName ) );
public void addNamedEntityGraph(String graphName, RootGraph<?> entityGraph) {
final RootGraphImplementor<?> rootGraph = (RootGraphImplementor<?>) entityGraph;
final EntityGraph<?> old = entityGraphMap.put( graphName, rootGraph.makeImmutableCopy( graphName ) );
if ( old != null ) {
log.debugf( "EntityGraph being replaced on EntityManagerFactory for name %s", graphName );
}
}

@Override
@SuppressWarnings("unchecked")
public <T> RootGraphImplementor<T> findEntityGraphByName(String name) {
return (RootGraphImplementor<T>) entityGraphMap.get( name );
public RootGraphImplementor<?> findEntityGraphByName(String name) {
return entityGraphMap.get( name );
}

@Override
public <T> List<RootGraphImplementor<? super T>> findEntityGraphsByJavaType(Class<T> entityClass) {
public <T> List<RootGraph<? super T>> findEntityGraphsByJavaType(Class<T> entityClass) {
final EntityDomainType<T> entityType = entity( entityClass );
if ( entityType == null ) {
throw new IllegalArgumentException( "Given class is not an entity: " + entityClass.getName() );
}
else {
final List<RootGraphImplementor<? super T>> results = new ArrayList<>();
for ( RootGraphImplementor<?> entityGraph : entityGraphMap.values() ) {
final List<RootGraph<? super T>> results = new ArrayList<>();
for ( var entityGraph : entityGraphMap.values() ) {
if ( entityGraph.appliesTo( entityType ) ) {
@SuppressWarnings("unchecked")
final RootGraphImplementor<? super T> result = (RootGraphImplementor<? super T>) entityGraph;
@SuppressWarnings("unchecked") // safe, we just checked
var result = (RootGraphImplementor<? super T>) entityGraph;
results.add( result );
}
}
Expand All @@ -434,10 +427,11 @@ public <T> Map<String, EntityGraph<? extends T>> getNamedEntityGraphs(Class<T> e
}
else {
final Map<String, EntityGraph<? extends T>> results = new HashMap<>();
for ( RootGraphImplementor<?> entityGraph : entityGraphMap.values() ) {
for ( var entityGraph : entityGraphMap.values() ) {
if ( entityGraph.appliesTo( entityType ) ) {
//noinspection unchecked
results.put( entityGraph.getName(), (EntityGraph<? extends T>) entityGraph );
@SuppressWarnings("unchecked") // safe, we just checked
var graph = (EntityGraph<? extends T>) entityGraph;
results.put( entityGraph.getName(), graph );
}
}
return results;
Expand Down Expand Up @@ -736,7 +730,9 @@ private <T> EntityDomainType<T> locateOrBuildEntityType(
MetadataContext context,
final TypeConfiguration typeConfiguration) {
@SuppressWarnings("unchecked")
final EntityDomainType<T> entityType = (EntityDomainType<T>) context.locateEntityType( persistentClass );
final EntityDomainType<T> entityType =
(EntityDomainType<T>)
context.locateEntityType( persistentClass );
return entityType == null
? buildEntityType( persistentClass, context, typeConfiguration )
: entityType;
Expand Down
Loading