Hibernate for Sybase DB中的多语句事务中不允许使用SELECT INTO命令 [英] SELECT INTO command not allowed within multi-statement transaction in Hibernate for Sybase DB
问题描述
我刚进入休眠模式,并尝试使用休眠模式从Java文件到Sybase DB执行一个过程.当我尝试运行该应用程序时,出现如下错误
I was new to hibernate and trying to execute an procedure from a Java file using hibernate to a Sybase DB. While i am trying to run the application i am getting an error like below
存储过程'dbo.p_chklist_test'只能在未链接的事务模式下运行. "SET CHAINED OFF"命令将导致当前会话使用未链接的交易模式.
我已经签入了几个论坛,并通过运行以下命令将模式设置为任何模式". sp_procxmode p_chklist_test,"anymode"
I have checked in few forums and set the mode as "Any mode" by running below command. sp_procxmode p_chklist_test, "anymode"
我还在休眠状态下将自动提交"设置为False.
Also i have set the Auto Commit as False in hibernate.
现在我遇到了类似下面的错误
Now i am getting a different error like below
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命令,并在配置xml中将参数"ServerInitiatedTransactions" 设置为false >
I have check few sites for the error SELECT INTO command not allowed within multi-statement transaction and set the parameter "ServerInitiatedTransactions" as false in the configuration xml
**<ConnectProperties>
<Property name="ServerInitiatedTransactions">false</Property>
</ConnectProperties>**
但是,这甚至可以解决问题,并且我遇到了相同的错误.有人可以帮我这个忙吗?
But this even dint resolve the issue and i am getting the same error. Can someone please help me on this.
我的代码:
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();
预先感谢!
推荐答案
请检查您的存储过程中是否有类似
Please check your stored procedure for statements like
从学生中选择ID到#a中.
SELECT id INTO #a FROM students.
从数据库的角度来看,此语句是可以的,但是当从Java程序执行时,此语句将无法工作并给出上述错误.
This statement is okay from DB perspective but when executed from a Java Program this won't work and give the above error.
首先,定义临时表
创建表#a( ID INT )
CREATE TABLE #a( id INT )
插入#a 从学生中选择ID
INSERT INTO #a SELECT id FROM students
以上修复程序有效.
这篇关于Hibernate for Sybase DB中的多语句事务中不允许使用SELECT INTO命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!