document not saving in spring jpa document manager application

前端 未结 4 2003
情歌与酒
情歌与酒 2020-12-10 13:38

I am developing a document management application in spring using jpa and MySQL. The application is currently accepting a document an

4条回答
  •  遥遥无期
    2020-12-10 14:45

    @CodeMed, it took me a while, but I was able to reproduce the issue. It might be a configuration issue : @PersistenceContext might be scanned twice, it might be scanned by your root-context and your web-context. This cause the @PersistenceContext to be shared, therefore it is not saving your data (Spring doesn't allow that). I found it weird that no messages or logs where displayed . if you tried this snippet below on you Save(Document document) you will see the actual error :

    Session session = this.em.unwrap(Session.class);
    session.persist(document);
    

    To solve the problem, you can do the following (avoid the @PersistenceContext to be scanned twice) :

    1- Make sure that all your controller are in a separate package like com.mycompany.myapp.controller, and in your web-context use the component-scan as

    2- Make sure that others component are in differents package other than the controller package , for example : com.mycompany.myapp.dao, com.mycompany.myapp.service .... and then in your root-context use the component-scan as

    Or show me yours spring xml configurations and your web.xml, I will point you to the right direction

提交回复
热议问题