PostgreSQL Hibernate错误:“无法在事务中间更改事务隔离级别”

时间:2012-11-16 08:16:44

标签: hibernate postgresql jdbc

我已经将PostgreSQL中的OID列映射到Hibernate中的Blob。有了它,我可以创建新的行来存储二进制数据并将其检索回来。但是当我尝试更新同一行或通过休眠删除行时,我得到了上面的错误。我使用Hibernate 3.2和PostgreSQL驱动程序9.2-1001 jdbc4驱动程序。在阅读有关读取oid类型的hibernate错误的基础上,我已升级到Hibernate 3.6.10但仍然得到相同的错误。

现在进行研究时,我发现hibernate在使用OID类型的PG jdbc驱动程序时无法检索数据。有人建议我们在hibernate中使用“byte []”作为映射类型,并将列更改为“bytea”。但是我不想映射到byte [],因为它会在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

更新

试图关注@a_horse_with_no_name建议。 尝试使用bytea列并在此Hibernate, Postgresql: Column "x" is of type oid but expression is of type byte之后创建一个修改过的postgresql方言,但现在我收到错误 “列'binaryValue'的类型为bytea,但表达式的类型为bigint”,同时插入一行。

1 个答案:

答案 0 :(得分:1)

最后,我通过使用@a_horse_with_no_name的建议解决了我的问题。我将列更改为bytea并将bean属性更改为byte[]。我按原样离开了方言。我 再使用Blob和PostgreSQL。

通过此更改,我可以毫无问题地编辑/删除列。

  • PostgreSQL版本:9.2.1
  • PostgreSQL驱动程序版本:9.2-1001
  • Hibarnate版本:3.6.10