Well, really, it's a problem with not-all-uppercase column names. Given a class like the following:
@Entity
@Table(name = "\"GameSessions\"")
public final class GameSession {
@Id
@Column(name = "\"id\"", nullable = false, updatable = false)
private final String id;
@Version
@Column(name = "\"version\"")
private long version;
}
I get errors like this:
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: JDBC exception on Hibernate data access: SQLException for SQL [select "version" from "GameSessions" where "id" =?]; SQL state [S1000]; error code [-421]; could not retrieve version: [com.justdavis.karl.rpstourney.service.api.game.GameSession#cVCRbKTaNj]; nested exception is org.hibernate.exception.GenericJDBCException: could not retrieve version: [com.justdavis.karl.rpstourney.service.api.game.GameSession#cVCRbKTaNj]
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:369) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:240) ~[cxf-rt-transports-http-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223) ~[cxf-rt-transports-http-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:197) ~[cxf-rt-transports-http-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149) ~[cxf-rt-transports-http-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:167) ~[cxf-rt-transports-http-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286) ~[cxf-rt-transports-http-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:206) ~[cxf-rt-transports-http-3.0.0-milestone1.jar:3.0.0.milestone1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688) ~[javax.servlet-api-3.0.1.jar:3.0.1]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262) ~[cxf-rt-transports-http-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698) ~[jetty-servlet-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:519) [jetty-servlet-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564) [jetty-security-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1097) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:446) [jetty-servlet-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1031) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.Server.handle(Server.java:445) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:269) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229) [jetty-server-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358) [jetty-io-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) [jetty-util-9.0.6.v20130930.jar:9.0.6.v20130930]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) [jetty-util-9.0.6.v20130930.jar:9.0.6.v20130930]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_55]
Caused by: org.apache.cxf.interceptor.Fault: JDBC exception on Hibernate data access: SQLException for SQL [select "version" from "GameSessions" where "id" =?]; SQL state [S1000]; error code [-421]; could not retrieve version: [com.justdavis.karl.rpstourney.service.api.game.GameSession#cVCRbKTaNj]; nested exception is org.hibernate.exception.GenericJDBCException: could not retrieve version: [com.justdavis.karl.rpstourney.service.api.game.GameSession#cVCRbKTaNj]
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:210) ~[cxf-rt-frontend-jaxrs-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:98) ~[cxf-rt-frontend-jaxrs-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
... 28 common frames omitted
Caused by: org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [select "version" from "GameSessions" where "id" =?]; SQL state [S1000]; error code [-421]; could not retrieve version: [com.justdavis.karl.rpstourney.service.api.game.GameSession#cVCRbKTaNj]; nested exception is org.hibernate.exception.GenericJDBCException: could not retrieve version: [com.justdavis.karl.rpstourney.service.api.game.GameSession#cVCRbKTaNj]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:651) ~[spring-orm-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104) ~[spring-orm-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:516) ~[spring-orm-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) ~[spring-tx-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) ~[spring-tx-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:387) ~[spring-tx-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) ~[spring-tx-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:646) ~[spring-aop-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at com.justdavis.karl.rpstourney.service.app.game.GameSessionResourceImpl$$EnhancerByCGLIB$$37a71988.setMaxRounds(<generated>) ~[spring-core-4.0.0.RELEASE.jar:na]
at com.justdavis.karl.rpstourney.service.app.game.GameSessionResourceImpl$$FastClassByCGLIB$$2999371b.invoke(<generated>) ~[spring-core-4.0.0.RELEASE.jar:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:713) ~[spring-aop-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:646) ~[spring-aop-4.0.0.RELEASE.jar:4.0.0.RELEASE]
at com.justdavis.karl.rpstourney.service.app.game.GameSessionResourceImpl$$EnhancerByCGLIB$$7a477e3c.setMaxRounds(<generated>) ~[spring-core-4.0.0.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_55]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_55]
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) ~[cxf-core-3.0.0-milestone1.jar:3.0.0.milestone1]
... 33 common frames omitted
Caused by: org.hibernate.exception.GenericJDBCException: could not retrieve version: [com.justdavis.karl.rpstourney.service.api.game.GameSession#cVCRbKTaNj]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.getCurrentVersion(AbstractEntityPersister.java:1910) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.action.internal.EntityVerifyVersionProcess.doBeforeTransactionCompletion(EntityVerifyVersionProcess.java:58) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:715) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:389) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:516) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:105) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:77) ~[hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512) ~[spring-orm-3.1.4.RELEASE.jar:3.1.4.RELEASE]
... 55 common frames omitted
Caused by: java.sql.SQLException: Column not found: "version"
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb-2.3.1.jar:2.3.1]
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb-2.3.1.jar:2.3.1]
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb-2.3.1.jar:2.3.1]
at org.hsqldb.jdbc.JDBCResultSet.findColumn(Unknown Source) ~[hsqldb-2.3.1.jar:2.3.1]
at org.hsqldb.jdbc.JDBCResultSet.getLong(Unknown Source) ~[hsqldb-2.3.1.jar:2.3.1]
at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:74) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:267) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:258) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.getCurrentVersion(AbstractEntityPersister.java:1899) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
... 63 common frames omitted
Caused by: org.hsqldb.HsqlException: Column not found: "version"
at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.3.1.jar:2.3.1]
at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.3.1.jar:2.3.1]
... 72 common frames omitted
These errors don't pop up all the time-- I think it has something to do with whether or not locking is being used on the transaction, but I'm not 100% on that. It seems to be 100% reproducible in transactions managed by Spring's @Transactional annotation for whatever that's worth.
Anywhoways, I've tracked the problem down to the following code: org.hibernate.persister.entity.AbstractEntityPersister.getVersionSelectString(). If the column name is quoted, that field will include the quotes. When trying to extract the field from a ResultSet, as in org.hibernate.persister.entity.AbstractEntityPersister.getCurrentVersion(Serializable, SessionImplementor), it passes in the field name to ResultSet.getLong(...) (or whatever) with the quotes. That won't work; the quotes need to be stripped for those calls.
|