简体   繁体   中英

CommandLineRunner and Springboot issue with Hibernate - could not initialize proxy session - no session

I have created a Soap service in spring-boot using the following blog https://www.javacodegeeks.com/2016/07/writing-consuming-soap-webservice-spring.html

The Endpoint Publish Url

@Override
public void run(String... arg0) throws Exception {
    // TODO Auto-generated method stub      Endpoint.p
    Endpoint.publish("http://localhost:9000" +"/service/serve", new ServeWeb());

}

The WebService Class is as follows

@WebService
public class ServeWeb {

    @Autowired
    XyzService xyzService;


    @WebMethod(operationName="LOGIN")
    public List<String> userLogin(
            @WebParam(name = "uid")String uid, 
            @WebParam(name = "pwd")String pwd){ 

           System.out.println("uid == "+uid+"::::: pwd == "+pwd);
            List<String> userDetaillist =xyzService.userLogin(uid, pwd);
        return userDetaillist;
    }
}

In XyzService I am using

@PersistenceContext
private EntityManager em;

I am getting following Exception on console

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

The issue is with CommandLinerRunner and Spring Boot Entity Manager. Can anyone let me know how we could use same entity manger through command line runner

我喜欢这个解决方案,我在XyzService上使用了Spring注释@Transactional,它对我有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM