Following a query with LockModeType.OPTIMISTIC, an exception is raised during flush/commit if hibernate.globally_quoted_identifiers is true in Hibernate

Solution Verified - Updated -

Issue

  • For the persistence unit, hibernate.globally_quoted_identifiers is set to true.
  • An entity is defined with an @Version property.
  • A transactional query executed with LockModeType.OPTIMISTIC loads an instance of the versioned entity.
  • The following exception is raised (the below is an example when using Microsoft SQL Server but a similar exception occurs with other databases, e.g. Oracle)

    ... org.hibernate.exception.GenericJDBCException: could not retrieve version: [<ENTITY_PACKAGE.ENTITY_CLASS>#<IDENTIFIER>]
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
        at org.hibernate.persister.entity.AbstractEntityPersister.getCurrentVersion(AbstractEntityPersister.java:1899)
        at org.hibernate.action.internal.EntityVerifyVersionProcess.doBeforeTransactionCompletion(EntityVerifyVersionProcess.java:43)
        at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:954)
        at org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:525)
        at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2507)
        at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
        ...
    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The column name [<NAME_OF_VERSION_PROPERTY_HERE>] is not valid.
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:234)
        at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn(SQLServerResultSet.java:699)
        at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getLong(SQLServerResultSet.java:2353)
        at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:63)
        at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:249)
        at org.hibernate.persister.entity.AbstractEntityPersister.getCurrentVersion(AbstractEntityPersister.java:1887)
        ...
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 7
    • 6
  • Hibernate
    • 5
    • 4

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content