1414
1515import org .hibernate .FlushMode ;
1616import org .hibernate .Internal ;
17+ import org .hibernate .engine .spi .ExceptionConverter ;
18+ import org .hibernate .engine .spi .SessionFactoryImplementor ;
1719import org .hibernate .query .QueryArgumentException ;
1820import org .hibernate .query .QueryFlushMode ;
1921import org .hibernate .HibernateException ;
2830import org .hibernate .graph .spi .RootGraphImplementor ;
2931import org .hibernate .jpa .internal .util .ConfigurationHelper ;
3032import org .hibernate .jpa .internal .util .FlushModeTypeHelper ;
31- import org .hibernate .metamodel .RuntimeMetamodels ;
32- import org .hibernate .metamodel .model .domain .JpaMetamodel ;
3333import org .hibernate .metamodel .model .domain .ManagedDomainType ;
3434import org .hibernate .property .access .spi .BuiltInPropertyAccessStrategies ;
3535import org .hibernate .property .access .spi .Getter ;
@@ -112,10 +112,22 @@ protected AbstractCommonQueryContract(AbstractCommonQueryContract original) {
112112 this .queryOptions = original .queryOptions ;
113113 }
114114
115- public SharedSessionContractImplementor getSession () {
115+ public final SharedSessionContractImplementor getSession () {
116116 return session ;
117117 }
118118
119+ public final SessionFactoryImplementor getSessionFactory () {
120+ return session .getFactory ();
121+ }
122+
123+ public final TypeConfiguration getTypeConfiguration () {
124+ return session .getFactory ().getTypeConfiguration ();
125+ }
126+
127+ protected final ExceptionConverter getExceptionConverter () {
128+ return session .getExceptionConverter ();
129+ }
130+
119131 protected int getIntegerLiteral (JpaExpression <Number > expression , int defaultValue ) {
120132 if ( expression == null ) {
121133 return defaultValue ;
@@ -379,14 +391,16 @@ protected void applyGraph(String graphString, GraphSemantic graphSemantic) {
379391 );
380392 }
381393
382- final RuntimeMetamodels runtimeMetamodels = getSession ().getFactory ().getRuntimeMetamodels ();
383- final JpaMetamodel jpaMetamodel = runtimeMetamodels .getJpaMetamodel ();
394+ final var factory = getSessionFactory ();
384395
385- final String entityName = runtimeMetamodels .getImportedName ( graphString .substring ( 0 , separatorPosition ).trim () );
396+ final String entityName =
397+ factory .getMappingMetamodel ()
398+ .getImportedName ( graphString .substring ( 0 , separatorPosition ).trim () );
386399 final String graphNodes = graphString .substring ( separatorPosition + 1 , terminatorPosition );
387400
388- final RootGraphImpl <?> rootGraph = new RootGraphImpl <>( null , jpaMetamodel .entity ( entityName ) );
389- GraphParser .parseInto ( (EntityGraph <?>) rootGraph , graphNodes , getSession ().getSessionFactory () );
401+ final RootGraphImpl <?> rootGraph =
402+ new RootGraphImpl <>( null , factory .getJpaMetamodel ().entity ( entityName ) );
403+ GraphParser .parseInto ( (EntityGraph <?>) rootGraph , graphNodes , getSessionFactory () );
390404 applyGraph ( rootGraph , graphSemantic );
391405 }
392406
@@ -587,7 +601,7 @@ public QueryParameterImplementor<?> getParameter(String name) {
587601 return getParameterMetadata ().getQueryParameter ( name );
588602 }
589603 catch ( HibernateException e ) {
590- throw getSession (). getExceptionConverter ().convert ( e );
604+ throw getExceptionConverter ().convert ( e );
591605 }
592606 }
593607
@@ -608,7 +622,7 @@ public <T> QueryParameterImplementor<T> getParameter(String name, Class<T> type)
608622 return parameter ;
609623 }
610624 catch ( HibernateException e ) {
611- throw getSession (). getExceptionConverter ().convert ( e );
625+ throw getExceptionConverter ().convert ( e );
612626 }
613627 }
614628
@@ -619,7 +633,7 @@ public QueryParameterImplementor<?> getParameter(int position) {
619633 return getParameterMetadata ().getQueryParameter ( position );
620634 }
621635 catch ( HibernateException e ) {
622- throw getSession (). getExceptionConverter ().convert ( e );
636+ throw getExceptionConverter ().convert ( e );
623637 }
624638 }
625639
@@ -639,7 +653,7 @@ public <T> QueryParameterImplementor<T> getParameter(int position, Class<T> type
639653 return parameter ;
640654 }
641655 catch ( HibernateException e ) {
642- throw getSession (). getExceptionConverter ().convert ( e );
656+ throw getExceptionConverter ().convert ( e );
643657 }
644658 }
645659
@@ -652,7 +666,7 @@ public <T> QueryParameterImplementor<T> getParameter(int position, Class<T> type
652666 protected abstract boolean resolveJdbcParameterTypeIfNecessary ();
653667
654668 private <P > JavaType <P > getJavaType (Class <P > javaType ) {
655- return getSession (). getFactory (). getTypeConfiguration ().getJavaTypeRegistry ()
669+ return getTypeConfiguration ().getJavaTypeRegistry ()
656670 .getDescriptor ( javaType );
657671 }
658672
@@ -667,7 +681,7 @@ else if ( parameter.getPosition() != null ) {
667681 return locateBinding ( parameter .getPosition () );
668682 }
669683
670- throw getSession (). getExceptionConverter ().convert (
684+ throw getExceptionConverter ().convert (
671685 new IllegalArgumentException ( "Could not resolve binding for given parameter reference [" + parameter + "]" )
672686 );
673687 }
@@ -788,7 +802,7 @@ private boolean isInstance(Type<?> parameterType, Object value) {
788802 }
789803
790804 private NodeBuilder getNodeuilder () {
791- return getSession (). getFactory ().getQueryEngine ().getCriteriaBuilder ();
805+ return getSessionFactory ().getQueryEngine ().getCriteriaBuilder ();
792806 }
793807
794808 @ Override
@@ -835,7 +849,7 @@ public CommonQueryContract setParameter(int position, Object value) {
835849 }
836850
837851 private boolean isRegisteredAsBasicType (Class <?> valueClass ) {
838- return getSession (). getFactory (). getTypeConfiguration ().getBasicTypeForJavaType ( valueClass ) != null ;
852+ return getTypeConfiguration ().getBasicTypeForJavaType ( valueClass ) != null ;
839853 }
840854
841855 @ Override
@@ -1028,14 +1042,16 @@ public <P> CommonQueryContract setParameterList(int position, Collection<? exten
10281042 }
10291043
10301044 private <P > Type <P > getParamType (Class <P > javaType ) {
1031- final TypeConfiguration typeConfiguration = getSession ().getFactory ().getTypeConfiguration ();
1032- final BasicType <P > basicType = typeConfiguration .standardBasicTypeForJavaType ( javaType );
1045+ final BasicType <P > basicType =
1046+ getTypeConfiguration ()
1047+ .standardBasicTypeForJavaType ( javaType );
10331048 if ( basicType != null ) {
10341049 return basicType ;
10351050 }
10361051 else {
1037- final JpaMetamodel metamodel = getSession ().getFactory ().getJpaMetamodel ();
1038- final ManagedDomainType <P > managedDomainType = metamodel .managedType ( javaType );
1052+ final ManagedDomainType <P > managedDomainType =
1053+ getSessionFactory ().getJpaMetamodel ()
1054+ .managedType ( javaType );
10391055 if ( managedDomainType != null ) {
10401056 return managedDomainType ;
10411057 }
@@ -1157,7 +1173,7 @@ protected <T> Type<T> determineType(String namedParam, Class<? extends T> retTyp
11571173 type = getParameterMetadata ().getQueryParameter ( namedParam ).getHibernateType ();
11581174 }
11591175 if ( type == null && retType != null ) {
1160- type = getSession (). getFactory ().getMappingMetamodel ().resolveParameterBindType ( retType );
1176+ type = getSessionFactory ().getMappingMetamodel ().resolveParameterBindType ( retType );
11611177 }
11621178 if ( retType != null && !retType .isAssignableFrom ( type .getJavaType () ) ) {
11631179 throw new IllegalStateException ( "Parameter not of expected type: " + retType .getName () );
0 commit comments