【问题标题】:SELECT INTO command not allowed within multi-statement transaction in Hibernate for Sybase DB在 Hibernate for Sybase DB 的多语句事务中不允许 SELECT INTO 命令
【发布时间】:2014-03-03 13:25:31
【问题描述】:

我是 hibernate 的新手,我尝试使用 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 command not allowed within multi-statement transaction 并在配置 xml 中将参数 "ServerInitiatedTransactions" 设置为 false p>

**<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();

提前致谢!

【问题讨论】:

  • 我已经从 Sybase DB 运行了 exec p_chklist_test 命令,它工作正常,我得到了想要的结果。但是当我试图从 Java 中获取数据时,我遇到了这个问题。

标签: java sql hibernate sybase sap-ase


【解决方案1】:

请检查您的存储过程中是否有类似的语句

从学生中选择 id INTO #a。

从 DB 的角度来看,这个语句是可以的,但是当从 Java 程序执行时,这将不起作用并给出上述错误。

首先,定义临时表

创建表#a( ID INT )

插入#a 从学生中选择 id

上述修复有效。

【讨论】:

    【解决方案2】:

    我已经通过以下方式调用程序解决了这个问题。希望它可以帮助其他人弄清楚。

    SET CHAINED OFF exec p_qa_existing_items

    【讨论】:

      【解决方案3】:

      这可能是因为您应该“从不”尝试在事务(select @@transaction)打开时使用“select into”,从任何平台 Java 或任何其他应用程序调用它。

      我相信@swat 提供的解决方案几乎是您应该使用的,而不是 SET CHAINED OFF。据我了解,由于某种原因,SET CHAINED 处于 ON 状态,因此可能会在您的代码中产生影响。因此,当需要打开事务但您没有打开事务时,SP 中可能没有任何代码,因为 SET CHAINED 为 ON。

      您可以在 Sybase 中使用它 -

      创建过程测试过程 作为 从表中选择 * 到 #temp 返回 去

      开始翻译 执行 test_proc 提交翻译

      开始翻译 执行 test_proc 回滚传输

      (我现在没有 Sybase 环境,因此无法自己检查。但这绝对可以帮助您了解原因)

      【讨论】:

        【解决方案4】:

        我在使用 Jboss 时遇到了同样的问题,我无法更改程序,因为它是由客户提供的。在我的情况下,配置数据源以使用后问题停止了

        jta="false".
        

        【讨论】:

          猜你喜欢
          • 2019-01-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-28
          • 1970-01-01
          相关资源
          最近更新 更多