Interface HibernateAdapter
public interface HibernateAdapter
Adapter over the differences across Hibernate version changes that differ between Hibernate 7 and 8.
Implementations resolve the version-specific methods and classes reflectively when created, so an unsupported Hibernate version fails early instead of on first use.
- Since:
- 4.2
- Author:
- Oscar Fanchin, Christoph Strobl, Mark Paluch
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringType introduced in Hibernate 8 whose presence identifies that generation. -
Method Summary
Modifier and TypeMethodDescriptionasSelectionQuery(Query query) Return theSelectionQuerythatqueryexposes indirectly, or null if it exposes none.static HibernateAdaptercreate()Create the adapter for the Hibernate version on the classpath.getHqlString(Object query) Return the HQL string of a named SQM query memento.getQueryString(Object query) Return the query string of an SQM query.getSqlString(Object query) Return the SQL string of a named native query memento.getSqmStatement(Object query) Render the SQM statement of an SQM query or named SQM query memento as HQL.static booleanisHibernate8(ClassLoader classLoader) Detect whether Hibernate 8 is on the classpath.booleanisNamedNativeQuery(Object query) Whetherqueryis the memento of a named native query.booleanisNamedSqmQuery(Object query) Whetherqueryis the memento of a named HQL or criteria query.booleanisSqmQuery(Object query) Whetherqueryis an SQM query, that is, an HQL or criteria query.
-
Field Details
-
HIBERNATE_8_SQM_STATEMENT_ACCESS
Type introduced in Hibernate 8 whose presence identifies that generation.- See Also:
-
-
Method Details
-
isSqmQuery
Whetherqueryis an SQM query, that is, an HQL or criteria query. -
isNamedSqmQuery
Whetherqueryis the memento of a named HQL or criteria query. -
isNamedNativeQuery
Whetherqueryis the memento of a named native query. -
getQueryString
Return the query string of an SQM query. A criteria query reports the placeholder<criteria>instead of HQL. UsegetSqmStatement(Object)to render it. -
getHqlString
-
getSqlString
-
getSqmStatement
Render the SQM statement of an SQM query or named SQM query memento as HQL. This recovers the HQL of criteria queries, whose query string is only a placeholder.- Throws:
IllegalStateException- if the query carries no SQM statement.
-
asSelectionQuery
Return theSelectionQuerythatqueryexposes indirectly, or null if it exposes none. Hibernate 8 no longer lets selection queries implementSelectionQuerydirectly and exposes them throughMutationOrSelectionQueryinstead. Queries that implementSelectionQuerythemselves, as on Hibernate 7, answer null. Callers test for those first. -
create
Create the adapter for the Hibernate version on the classpath.- Throws:
IllegalStateException- if the Hibernate version is not supported.- See Also:
-
isHibernate8
Detect whether Hibernate 8 is on the classpath. The reported Hibernate version is checked first. Type presence serves as fallback because the reported version is not reliable in shaded or repackaged distributions.- Parameters:
classLoader- class loader for the presence check. 8.
-