Reputation: 31
I have mapped OID column in PostgreSQL to Blob in Hibernate. With that I can create new row to store binary data and retrieve it back. But when I try to update the same row or delete the row through hibernate, I get above error. I was using Hibernate 3.2 with PostgreSQL driver 9.2-1001 jdbc4 driver. Based on reading about hibernate bug with reading oid type, I have upgraded to Hibernate 3.6.10 but still get the same error.
Now when doing research, I found that hibernate had some problems with PG jdbc driver with OID type not able to retrieve data. It was suggested that we use "byte[]" as the mapping type in hibernate and change column to "bytea". But I do not want to map to byte[] as it would read the entire binary content in memroy.
2012-11-16 13:36:32,614 [main] INFO Cache - No object present with id=1295
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:345)
at $Proxy0.beginTransaction(Unknown Source)
at x.y.objectstore.dao.TransactionManager.begin(TransactionManager.java:53)
at x.y.objectstore.dao.BaseStore.load(BaseStore.java:122)
at x.y.objectstore.dao.BaseStore.load(BaseStore.java:110)
at x.y.objectstore.ConceptInstanceImpl.getContainerBean(ConceptInstanceImpl.java:284)
at x.y.objectstore.deletion.PropertyInstanceDeletionTask.run(PropertyInstanceDeletionTask.java:53)
at x.y.objectstore.deletion.DeletionService.executeDeletionTask(DeletionService.java:56)
at x.y.objectstore.ConceptInstanceImpl.deletePropertyInstance(ConceptInstanceImpl.java:726)
at x.y.objectstore.ConceptInstanceImpl.removeProperty(ConceptInstanceImpl.java:719)
at x.y.objectstore.tests.PropertyEditTests.testEditBinaryProperty(PropertyEditTests.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.postgresql.util.PSQLException: Cannot change transaction isolation level in the middle of a transaction.
at org.postgresql.jdbc2.AbstractJdbc2Connection.setTransactionIsolation(AbstractJdbc2Connection.java:929)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:126)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 36 more
Update:
Just tried to follow @a_horse_with_no_name suggestion. Tried with bytea column and following this Hibernate, Postgresql: Column "x" is of type oid but expression is of type byte to create a modified postgresql dialect but now I get error "column 'binaryValue' is of type bytea but expression is of type bigint" while inserting a row.
Upvotes: 2
Views: 3692
Reputation: 31
Finally I solved my problem by using @a_horse_with_no_name 's advice. I changed column to bytea
and changed the bean property to byte[]
. I left the dialect as it is. I do not use Blob
with PostgreSQL anymore.
With this changes I can edit/delete column without any problem.
9.2.1
9.2-1001
3.6.10
Upvotes: 1