Following a query with LockModeType.OPTIMISTIC, an exception is raised during flush/commit if hibernate.globally_quoted_identifiers is true in Hibernate
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7
- 6
- Hibernate
- 5
- 4
Issue
-
For the persistence unit,
hibernate.globally_quoted_identifiersis set totrue. -
An entity is defined with an
@Versionproperty. -
A transactional query executed with
LockModeType.OPTIMISTICloads 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) ...
Resolution
This issue will be addressed in a future release1.
Root Cause
This is a known defect (Content from hibernate.atlassian.net is not included.HHH-14616).
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.