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();
And now i get the following error:
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
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. I have made the same update using a transaction-enabled Informix DB and it works.
Disabling transaction support is very odd.
With EclipseLink you can disable transaction using a SessionCustomizer,
session.getLogin().useExternalTransactionController();
This will make EclipseLink think something else in managing transactions (normally JTA), but in your case, nothing...