0

I'm trying to do an update in my local database, but when I excute an "executeUpdate" I'm getting the next error :

javax.persistence.TransactionRequiredException: Exception Description: No externally managed transaction is currently active for this thread

This is my persistence.xml :

<?xml version="1.0" encoding="windows-1252" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
  <persistence-unit name="GestionPagoTramiteUtilImplementacion">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/servicioswebDS</jta-data-source>
    <class>modelo.Transferencias</class>
    <properties>
      <property name="eclipselink.target-server" value="WebLogic_10"/>
      <property name="javax.persistence.jtaDataSource" value="jdbc/servicioswebDS"/>
    </properties>
  </persistence-unit>
</persistence>

This is the Class Transferencias.java :

@Entity
@NamedQueries({
              @NamedQuery(name = "Transferencias.findAll", query = "select o from Transferencias o"), 
              @NamedQuery(name = "Transferencias.asociarPagoTramiteUpdate", query = "UPDATE  Transferencias o SET o.usado = :p_usado , o.cdgpraradicacion = :p_codigoParaRadicacion WHERE o.trazabilitycode = :p_identificadorTransaccion")
    })
public class Transferencias implements Serializable {


}

I have a SessionBean when I'm calling the class Transferencias Using an EntityManager

@Stateless(name = "PagoTramiteSession",
           mappedName = "InvimaPortafolioServicios-GestionPagoTramiteUtilImplementacion-PagoTramiteSession")
public class PagoTramiteSessionBean implements PagoTramiteSession, PagoTramiteSessionLocal {
    @Resource
    SessionContext sessionContext;
    @PersistenceContext(unitName = "GestionPagoTramiteUtilImplementacion")
    private EntityManager em;

    public PagoTramiteSessionBean() {
    }

    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public boolean actualizarPagoTramite(BigDecimal codigoParaRadicacion, String identificadorTransaccion,
                                         String usado) throws SQLException {
        try {
            Query query;
//            String sql =
//                "UPDATE Transferencias t " + " SET t.usado = :p_usado, " +
//                "t.cdgpraradicacion = :p_codigoParaRadicacion " +
//                " WHERE t.trazabilitycode = :p_identificadorTransaccion";
//            query = em.createQuery(sql);
//            query.setParameter("p_usado", usado);
//            query.setParameter("p_codigoParaRadicacion", codigoParaRadicacion);
//            query.setParameter("p_identificadorTransaccion", identificadorTransaccion);
//            int retorno = query.executeUpdate();
//            if (retorno >= 1) {
//                return true;
//            } else {
//                return false;
//            }
            query = em.createNamedQuery("Transferencias.asociarPagoTramiteUpdate");
            query.setParameter("p_usado", usado);
            query.setParameter("p_codigoParaRadicacion", codigoParaRadicacion);
            query.setParameter("p_identificadorTransaccion", identificadorTransaccion);
            int retorno = query.executeUpdate();
            if (retorno >= 1) {
                return true;
            } else {
                return false;
            }


        } catch (Exception e) {
            System.out.println(e);
        }
        return false;
    }


}

I have tried to execute the update in two ways, using a nativeQuery and using a createQuery method by entityManager.

When I execute a em.getResultList() this works fine, but when I'm trying to do an update I have the error.

Punit
  • 324
  • 1
  • 4
  • 17
Allanh
  • 465
  • 1
  • 7
  • 19
  • 1
    `@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)` **???????** – Alan Hay Sep 26 '17 at 16:45
  • 1
    Remove @TransactionAttribute(...). – ujulu Sep 26 '17 at 16:55
  • I removed this anotation and I could update. It was a stupid error, if you want, you can answer the question and I'm going to give you the correct answer, thanks so much. – Allanh Sep 26 '17 at 19:43

1 Answers1

0

You have not specified a transaction manager

You need something like

<persistence-unit name="GestionPagoTramiteUtilImplementacion" transaction-type="RESOURCE_LOCAL">>

See http://www.eclipse.org/eclipselink/documentation/2.5/solutions/testingjpa002.htm

Essex Boy
  • 7,565
  • 2
  • 21
  • 24
  • Hi Essex Boy, thanks for reply. I have a `Persistence-unit` with that name in my `persistence.xml`, I added the property `transaction-type="RESOURCE_LOCAL"` but I have the same error – Allanh Sep 26 '17 at 15:39