TransactionRequiredException Executing an update/delete query

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

    import org.hibernate.Criteria;
    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;
    import org.springframework.transaction.annotation.Transactional;
    
    
        @Transactional
        public int changepassword(String password, long mobile) {
            // TODO Auto-generated method stub
            session = factory.getCurrentSession();
            Query query = session.createQuery("update User u set u.password='" + password + "' where u.mobile=" + mobile);
            int result = query.executeUpdate();
    
            return result;
        }
    add this code 200% it will work... might scenario is diff but write like this:)
    

提交回复
热议问题