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 Details

    • HIBERNATE_8_SQM_STATEMENT_ACCESS

      static final String HIBERNATE_8_SQM_STATEMENT_ACCESS
      Type introduced in Hibernate 8 whose presence identifies that generation.
      See Also:
  • Method Details

    • isSqmQuery

      boolean isSqmQuery(Object query)
      Whether query is an SQM query, that is, an HQL or criteria query.
    • isNamedSqmQuery

      boolean isNamedSqmQuery(Object query)
      Whether query is the memento of a named HQL or criteria query.
    • isNamedNativeQuery

      boolean isNamedNativeQuery(Object query)
      Whether query is the memento of a named native query.
    • getQueryString

      String getQueryString(Object query)
      Return the query string of an SQM query. A criteria query reports the placeholder <criteria> instead of HQL. Use getSqmStatement(Object) to render it.
    • getHqlString

      String getHqlString(Object query)
      Return the HQL string of a named SQM query memento.
    • getSqlString

      String getSqlString(Object query)
      Return the SQL string of a named native query memento.
    • getSqmStatement

      String getSqmStatement(Object query)
      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

      @Nullable SelectionQuery<?> asSelectionQuery(Query query)
      Return the SelectionQuery that query exposes indirectly, or null if it exposes none. Hibernate 8 no longer lets selection queries implement SelectionQuery directly and exposes them through MutationOrSelectionQuery instead. Queries that implement SelectionQuery themselves, as on Hibernate 7, answer null. Callers test for those first.
    • create

      static HibernateAdapter create()
      Create the adapter for the Hibernate version on the classpath.
      Throws:
      IllegalStateException - if the Hibernate version is not supported.
      See Also:
    • isHibernate8

      static boolean isHibernate8(ClassLoader classLoader)
      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.