我已將PostgreSQL中的OID列映射到Hibernate中的Blob。有了這個,我可以創建新的行來存儲二進制數據並將其恢復。但是,當我嘗試更新相同的行或通過休眠刪除行時,我得到以上錯誤。我使用Hibernate 3.2和PostgreSQL驅動程序9.2-1001 jdbc4驅動程序。基於讀取oid類型的hibernate bug,我已經升級到Hibernate 3.6.10,但仍然得到相同的錯誤。PostgreSQL Hibernate錯誤:「無法在事務中間更改事務隔離級別」
現在在做研究的時候,我發現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方言,但現在我得到錯誤 「column」binaryValue'類型爲bytea,但表達式類型爲bigint「,同時插入一行。
OID(又名 「大物」)是斑點一個不錯的選擇。改用'bytea'。應該可以將它映射到Hibernate中的blob。搜索這個網站(和網絡),這個問題定期出現 –
考慮直接使用JDBC。另外,當你發表類似「做研究時,我發現」...請*提供* *鏈接*。對於我們,以及任何後來發現你的問題的人。 –
@CraigRinger下面是我遇到的一些鏈接。 [https://hibernate.onjira.com/browse/HHH-4876](https://hibernate.onjira.com/browse/HHH-4876) –