TransactionRequiredException exception when executing an update: javax.persistence.TransactionRequiredException: Executing an update / delete query

0

I am trying to execute an update query to a database with hibernate but it turns out that it shows me the following transaction exception and does not update me. I'm working with jboss, hibernate. I've tried to follow up with transaction, begin, commit, placing the @Transactional tag on the method, placing joinTransaction () before the executeUpdate () statement but nothing.

They are very grateful for your help. :)

  

Method that I am calling and that performs the update query without the joinTransaction () tag before the executeUpdate ()

@Transactional
public int modificarClubVirtualReality(Clase c, boolean valor){

            int updated = 0;

            try {

            javax.persistence.Query q = this.getEntityManager().createQuery("UPDATE Clase c SET c.clubVirtualReality =:valor WHERE c.codigo =:codigo");
            q.setParameter("valor", valor); 
            q.setParameter("codigo", c.getCodigo().intValue());         

            q.executeUpdate();


            } catch (PersistenceException e) {

                e.printStackTrace();
            }

    return updated;     
}
  

Error exiting

14:50:06,589 ERROR [stderr] (MSC service thread 1-13) 
javax.persistence.TransactionRequiredException: Executing an update/delete 
query

14:50:06,589 ERROR [stderr] (MSC service thread 1-13)   at 
org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:96)

14:50:06,590 ERROR [stderr] (MSC service thread 1-13)   at com.kubesoft.jamestown.action.home.ClaseHome.modificarClubVirtualReality(ClaseHome.java:126)

14:50:06,590 ERROR [stderr] (MSC service thread 1-13)   at 
com.kubesoft.jamestown.action.tiempo.Controlador.init(Controlador.java:108)
  

When I put the joinTransaction () statement before the executeUpdate () the previous one does not come out anymore but this comes out.

No active JTA transaction on joinTransaction call
  

Main method in another class that calls the method ModClubVirtualReality (class, true);

int n = 5014;
Integer numeroclase = new Integer(n);
ClaseHome clasehome = new ClaseHome();
//Obtengo el tipo clase para hacerle un update en uno de sus campos en base 
de datos
Clase clase = clasehome.obtenerClase(numeroclase);
clasehome.modificarClubVirtualReality(clase, true)
    
asked by Francisco Javier Duarte Garcia 02.11.2018 в 21:28
source

0 answers