Thom
Thom

Reputation: 15072

hibernate exception during commit

We are using Spring 2.5.6 and the Hibernate that comes with it.

As part of our architecture, we have a service and a manager. The service calls the manager to provide a unit of work. We place an AOP interceptor around the manager to manage the transaction.

In our case, the manager is creating an image and a note that links that image to a person, then returning back to the service. These are brand new functions.

When I run this I get the following stack trace:

2013-07-11 08:06:52,969 3773870 ERROR org.hibernate.event.def.AbstractFlushingEventListener | Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
        at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy50.attachImage(Unknown Source)
        at com.acs.gs.juror.service.person.impl.PersonServiceImpl$1.retry(PersonServiceImpl.java:557)
        at com.acs.gs.juror.service.Service.withRetry(Service.java:362)
        at com.acs.gs.juror.service.person.impl.PersonServiceImpl.attachImage(PersonServiceImpl.java:562)
        at com.xerox.tclg.juror.servlet.StoreImageServlet.handleRequestInternal(StoreImageServlet.java:73)
        at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.BatchUpdateException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
        at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10345)
        at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:230)
        at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
        at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
        at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
        ... 41 more

When I searched on the error, I found a lot entries about queries with null values. The thing is that I've already done the inserts and that worked fine. It's throwing this exception during the commit.

Both image and note are existing fields that I've used in the past. I have recently put a link on note to image so that a note may reference an image.

Just because of the error message, I'm suspicious of the image. Here is the definition of the image data field on the image:

  @Column( name = "IMAGE_DATA" )
  @Lob()
  private byte[ ] imageData;

I'd appreciate any advice as to how to proceed.

Upvotes: 1

Views: 1163

Answers (2)

Thom
Thom

Reputation: 15072

The problem ended up involving a missing annotation.

I had just added an image to note entry and set it up to point to the UUID of the image, but left off @OneToOne. As such, it appeared to be trying to store the image data in a field for UUID.

I Added the @OneToOne and the problem went away. Nathan was also correct in saying that it wasn't actually getting inserted until the commit. To find the issue, I moved these inserts outside of the transaction so that they got inserted immediately. This helped me track down the issue.

Upvotes: 0

mthmulders
mthmulders

Reputation: 9705

The key to the answer is in the lower part of the stacktrace:

ORA-00932: inconsistent datatypes: expected NUMBER got BINARY

Hard to say which field this is about, but since you're working with images there may be something wrong in how you configured persistence for that class / field.

Maybe you should hint Hibernate how to store the field by annotating it with

@Lob(type = LobType.BLOB)

Upvotes: 2

Related Questions