@After public void tearDown() throws Exception { if (em != null) { em.close(); } if (emFactory != null) { emFactory.close(); } try { connection.createStatement().execute("SHUTDOWN"); } catch (Exception ex) { } }
@Before public void setUp() throws Exception { try { Class.forName("org.hsqldb.jdbcDriver"); connection = DriverManager.getConnection("jdbc:hsqldb:mem:unit-testing-jpa", "sa", ""); } catch (Exception ex) { ex.printStackTrace(); fail("Exception during HSQL database startup."); } try { emFactory = Persistence.createEntityManagerFactory("MyPersistence"); em = emFactory.createEntityManager(); } catch (Exception ex) { ex.printStackTrace(); fail("Exception during JPA EntityManager instanciation."); } }