我是新来的冬眠者,尝试使用hibernate从Java文件到Sybase DB执行过程。当我尝试运行该应用程序时,出现如下错误
存储过程’dbo.p_chklist_test’只能在未链接的事务模式下运行。 “ SET CHAINED OFF”命令将导致当前会话使用未链接的事务模式。
我已经登录了几个论坛,并通过运行以下命令将该模式设置为“任何模式”。sp_procxmode p_chklist_test,“任意模式”
另外,我在休眠状态下将“自动提交”设置为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命令, 并在配置xml中将参数 “ ServerInitiatedTransactions”设置 为false
**<ConnectProperties> <Property name="ServerInitiatedTransactions">false</Property> </ConnectProperties>**
但这甚至可以解决问题,而我也遇到了同样的错误。有人可以帮我这个忙吗?
我的代码:
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();
提前致谢!
请检查您的存储过程中的语句,例如
从学生中选择ID到#a中。
从数据库的角度来看,此语句是可以的,但是当从Java程序执行时,此语句将不起作用并出现上述错误。
首先,定义临时表
创建表#a(id INT)
从学生中插入#a选择ID
上面的修复程序有效。