What is the proper way to close H2?

前端 未结 5 1954
我在风中等你
我在风中等你 2020-12-15 04:25

This is related to this post.
I think I am having problem with H2 meaning that it does not close properly.
I suspect this since I see myDB.lock.db

5条回答
  •  感动是毒
    2020-12-15 05:16

    Not sure if this is relevant to your situation but have you tried adding a DBStarter listener?

    http://www.h2database.com/html/tutorial.html, see the "Using a Servlet Listener to Start and Stop a Database" section.

    The link suggests adding the following to web.xml:

    
        org.h2.server.web.DbStarter
    
    

    Please see discussion here (admittedly from 2008 so may be out of date) - apparently the fix applies to both embedded and non-embedded instances: http://groups.google.com/group/h2-database/browse_thread/thread/eb609d58c96f4317

    Alternatively how are you using the connections? Are you sure you are cleaning up the connections properly?

    I was having issues before, in my case I was using the connection with a JPA EntityManager and I forgot to close the EntityManager instance after use, which resulted in some issues:

    @PersistenceUnit(unitName="myEm")
    private EntityManagerFactory emf;
    
    public void doStuff() {
        EntityManager em = emf.createEntityManager();
        ...
        em.close(); // forgot this line
    }
    

提交回复
热议问题