Informix上的JPA事务 [英] JPA Transactions on Informix

查看:84
本文介绍了Informix上的JPA事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Java SE 7.0环境中使用JPA 2.0和EclipseLink 3.0在表上进行更新,并使用Non-Transactional Informix DB v。11.50,persistence.xml为:

I need to make an update on a table using JPA 2.0 with EclipseLink 3.0 on a Java SE 7.0 environment, using Non-Transactional Informix DB v. 11.50, the persistence.xml is:


<persistence-unit name="pp_pu" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>...</class>
    <class>...</class>
    <properties>
        <property name="javax.persistence.jdbc.url"
                  value="jdbc:informix-sqli://10.191.78.230:40494/ptpr:informixserver=online_ptpr"/>
        <property name="javax.persistence.jdbc.driver" value="com.informix.jdbc.IfxDriver"/>
        <property name="javax.persistence.jdbc.user" value="test"/>
        <property name="javax.persistence.jdbc.password" value="test"/>
    </properties>
</persistence-unit>

当我尝试制作更新时出现以下错误:

And when i try to make an update I get the following error:

Exception in thread "main" javax.persistence.TransactionRequiredException: 
Exception Description: No transaction is currently active
    at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.throwCheckTransactionFailedException(EntityTransactionWrapper.java:113)
    at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.checkForTransaction(EntityTransactionWrapper.java:50)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.checkForTransaction(EntityManagerImpl.java:1776)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeUpdate(EJBQueryImpl.java:533)

然后我尝试使用以下方法解决错误:

Then i try to solve the error with the following:

em.getTransaction().begin();
// Update query
em.getTransaction().commit();

现在我得到以下错误:

Internal Exception: java.sql.SQLException: Transactions not supported
Error Code: -79744
Exception in thread "main" Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Transactions not supported
Error Code: -79744
Query: DataModifyQuery(sql="update tg_proteccion_cv
set i_eq_validados=?,
    i_eq_a_protegidos=?
where v_id_proteccion=?
    and v_cve_cliente=?")
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicBeginTransaction(DatabaseAccessor.java:230)
    at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.beginTransaction(DatasourceAccessor.java:239)
    at org.eclipse.persistence.internal.sessions.AbstractSession.basicBeginTransaction(AbstractSession.java:479)
    at org.eclipse.persistence.sessions.server.ClientSession.addWriteConnection(ClientSession.java:646)
    at org.eclipse.persistence.sessions.server.ServerSession.acquireClientConnection(ServerSession.java:246)
    at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:226)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeNoSelectCall(DatasourceCallQueryMechanism.java:236)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeNoSelect(DatasourceCallQueryMechanism.java:216)
    at org.eclipse.persistence.queries.DataModifyQuery.executeDatabaseQuery(DataModifyQuery.java:85)
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:829)
    at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:728)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2863)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1501)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1483)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1457)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeUpdate(EJBQueryImpl.java:540)
    at com.telcel.gsa.dsiee.pprecios.amb_alt.FixProtsCv.updateCV(FixProtsCv.java:70)
    at com.telcel.gsa.dsiee.pprecios.amb_alt.FixProtsCv.fix(FixProtsCv.java:88)
    at com.telcel.gsa.dsiee.pprecios.amb_alt.FixProtsCv.main(FixProtsCv.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.sql.SQLException: Transactions not supported
    at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:348)
    at com.informix.jdbc.IfxSqliConnect.setAutoCommit(IfxSqliConnect.java:1333)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicBeginTransaction(DatabaseAccessor.java:223)
    ... 25 more

我使用JDBC进行更新没问题,JPA是否支持Non-Transactiona DB的?
出于性能原因,DBA关闭了Informix上的事务支持,并且这种情况不会改变。
那么,我有什么想念的吗?

I have no problem doing the update using JDBC, ¿does JPA support Non-Transactional DB's? For performance reasons the DBA has turned off transaction support on Informix, and that isn't going to change. So, is there anything i'm missing? what's wrong?

P.D。
我已经使用启用了事务的Informix数据库进行了相同的更新,并且可以正常工作。

P.D. I have made the same update using a transaction-enabled Informix DB and it works.

推荐答案

禁用事务支持是

使用EclipseLink,您可以使用SessionCustomizer禁用事务,

With EclipseLink you can disable transaction using a SessionCustomizer,

session.getLogin().useExternalTransactionController();

这将使EclipseLink在管理事务时考虑其他问题(通常是JTA),但在您的情况下,什么也没有...

This will make EclipseLink think something else in managing transactions (normally JTA), but in your case, nothing...

这篇关于Informix上的JPA事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆