我是hibernate的新手,嘗試從使用hibernate的Java文件執行過程到Sybase數據庫。當我嘗試運行應用程序時,出現如下錯誤不允許在Hibernate for Sybase DB的多語句事務中使用SELECT INTO命令
存儲過程'dbo.p_chklist_test'可能只能在非鏈式事務模式下運行。 'SET CHAINED OFF'命令將導致當前會話使用非鏈式事務模式。
我已經檢查了幾個論壇,並通過運行下面的命令將模式設置爲「任何模式」。 sp_procxmode p_chklist_test,「anymode」
此外,我已將自動提交設置爲False在休眠。
現在我得到一個不同的錯誤,如下面
Caused by: org.hibernate.exception.GenericJDBCException: could not execute native bulk manipulation query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:198)
at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1191)
at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:357)
at com.lcit_release.server.dao.ReleaseItemDao.searchRecordsNew(ReleaseItemDao.java:198)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy8.searchRecordsNew(Unknown Source)
at com.lcit_release.server.logic.ReleaseItemLogic.searchExisting(ReleaseItemLogic.java:147)
at com.lcit_release.server.adapter.ReleaseItemLogicAdapter.search(ReleaseItemLogicAdapter.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
... 41 more
**Caused by: com.sybase.jdbc3.jdbc.SybSQLException: SELECT INTO command not allowed within multi-statement transaction.**
at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.updateLoop(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.executeUpdate(Unknown Source)
at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeUpdate(Unknown Source)
at msjava.tools.db.jdbc3.MSDBPreparedStatementImpl.executeUpdate(MSDBPreparedStatementImpl.java:315)
at msjava.tools.db.jdbc3.MSDBPreparedStatement.executeUpdate(MSDBPreparedStatement.java:78)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:189)
... 62 more
我檢查錯誤幾個網站SELECT INTO命令多語句事務中不允許和設置參數「ServerInitiatedTransactions」爲在配置xml錯誤
**<ConnectProperties>
<Property name="ServerInitiatedTransactions">false</Property>
</ConnectProperties>**
但這甚至dint解決了這個問題,我得到同樣的錯誤。有人能幫助我嗎?
我的代碼:
String sql3 ="exec dbo.p_chklist_test";
System.out.println("sql 3 is "+sql3);
Query query = sessionFactory.getCurrentSession().createSQLQuery(sql3);
sessionFactory.getCurrentSession().connection().setAutoCommit(false);
query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
listRelItem = query.list();
先謝謝了!
我已經運行exec命令p_chklist_test形成的Sybase數據庫後停止,它是工作很好,我得到期望的結果。但是,當我試圖從Java獲取數據時,我正面臨着這個問題。 –