在postgresql 9.3中插入数据时出错

时间:2014-06-30 11:12:24

标签: hibernate postgresql jdbc postgresql-9.3 enterprisedb

目前我正在使用PostgreSQL Professional Advanced Server(PPAS)9.3(PostgreSQL 9.3的修改版本)。

我试图在postgresql数据库中插入一行并出现以下错误:

error log:
javax.ejb.EJBTransactionRolledbackException: [2] An exception has occurred: ERROR: current transaction is aborted, commands ignored until end of transaction
block
        at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
        at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
        at org.jboss.aspects.tx.TxInterceptor$Supports.invoke(TxInterceptor.java:148)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
        at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
        at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
        at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
        at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
        at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
        at java.lang.Thread.run(Thread.java:662)
Caused by: com.code.Exception: [2] An exception has occurred: ERROR: current transaction is aborted, commands ignored until end of transaction bl
ock
        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.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
        at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
        at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
        at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
        at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
        at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
        ... 75 more
Caused by: org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559)
     org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
        at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342)

        ... 95 more

我首先尝试创建begin transaction对象,然后如果出现异常则回滚它没有帮助我。

即使我使用单个插入语句。我知道,如果以前的语句无法执行,那么这个错误就会出现,但在我的情况下,我只有一个语句,但我也得到了同样的错误。

这是仅在postgresql中不起作用的代码,我们在oracle和sql server中使用相同的代码,这是有效的。是的我在ppas上执行了相同的查询,它没有任何错误地执行。在此之前,我们已经执行了一个错误的语句,但之后我们关闭了连接

请帮助我?

2 个答案:

答案 0 :(得分:1)

此:

  

引起:org.postgresql.util.PSQLException:错误:当前事务中止,命令被忽略直到事务块结束

表示先前的语句失败,并且您的代码未捕获异常并发出ROLLBACK。因此,它试图继续使用处于中止状态的交易。

当autocommit关闭时,PostgreSQL在语句失败后需要显式ROLLBACK。它永远不会隐式回滚并启动新事务。它不能忽略有错误的语句并继续执行事务 - 必须中止和重试整个事务(除非您手动使用保存点)。

这与许多数据库不同,因此它可能暴露了代码中的底层错误,它会导致ERROR,然后忽略错误并继续。查看PostgreSQL服务器错误日志,看看第一个错误是什么,以及它是什么声明。

答案 1 :(得分:0)

经过一个多月的谷歌搜索和R& D之后,我终于通过在PPAS9.3 postgresql中将“edb_stmt_level_tx = off”的值设置为“on”来修复上述postgresql 9.3的常见错误。 .config属性文件。有关更多信息,请访问以下链接。 欲了解更多信息,请visit this link