java - JPA连接数据库,一段时间没有数据操作会关闭连接,再次访问就会抛出异常,如何解决?
阿神
阿神 2017-04-18 10:53:15
0
1
720

使用JPA规范的DataNucleus框架实现DAO层,如果一直保持连接,两天之后,会抛出异常,下面是配置:

        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/book_store?characterEncoding=utf-8"/>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="root"/>
        <property name="datanucleus.connectionPoolingType" value="tomcat"/>
        <property name="datanucleus.schema.autoCreateAll" value="true"/>
        <property name="datanucleus.connectionPool.maxPoolSize" value="5"/>
        <property name="datanucleus.connectionPool.maxIdle" value="10"/>
        <property name="datanucleus.connectionPool.leakThreshold" value="1"/>
        <property name="datanucleus.connectionPool.maxLifetime" value="240"/>
        <property name="datanucleus.schema.autoCreateAll" value="true"/>
        

这是报错信息:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.persistence.PersistenceException: No operations allowed after connection closed.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:980)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
阿神
阿神

闭关修行中......

reply all(1)
PHPzhong

Have you turned it off entityManager?

 entitymanager.close();

Make sure to put something like this at the back

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template