TransactionRequiredException Executing an update/delete query

后端 未结 20 2140
没有蜡笔的小新
没有蜡笔的小新 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:42

    You need not to worry about begin and end transaction. You have already apply @Transactional annotation, which internally open transaction when your method starts and ends when your method ends. So only required this is to persist your object in database.

     @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    
             public String persist(Details details){
                 details.getUsername();
                 details.getPassword();
                 Query query = em.createNativeQuery("db.details.find(username= "+details.getUsername()+"& password= "+details.getPassword());
    
                 em.persist(details);
                 System.out.println("Sucessful!");
                return "persist";        
         }
    

    EDIT : The problem seems to be with your configuration file. If you are using JPA then your configuration file should have below configuration

    
    
    
        
            
        
        
    
    
    

提交回复
热议问题