TransactionRequiredException Executing an update/delete query

后端 未结 20 2141
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 15:29

Hi I am using hibernate JPA with spring and mongodb and i am running my application on Glassfish-4.0.

My service class is :

@Component
public class T         


        
20条回答
  •  我在风中等你
    2020-12-02 15:54

    Error message while running the code:

    javax.persistence.TransactionRequiredException: Executing an update/delete query

    Begin the entityManager transaction -> createNativeQuery -> execute update -> entityManager transaction commit to save it in your database. It is working fine for me with Hibernate and postgresql.

    Code

    entityManager.getTransaction().begin();
    Query query = entityManager.createNativeQuery("UPDATE tunable_property SET tunable_property_value = :tunable_property_value WHERE tunable_property_name = :tunable_property_name");
    query.setParameter("tunable_property_name", tunablePropertyEnum.eEnableJobManager.getName());
    query.setParameter("tunable_property_value", tunable_property_value);
    query.executeUpdate();
    entityManager.getTransaction().commit();
    

提交回复
热议问题