JacobBosma (4) [Avatar] Offline
I am running the examples. (mvn clean test)
In the previous (first) edition of the book/sourcecode there are nice ant tasks :
startdb, schemaexport,dbmanager (and run). So I can see in the database what has happened, been generated/inserted.

How can I browse the database with the second edition source code ?
Christian Bauer (56) [Avatar] Offline
Re: How access database
Double click on the H2.jar file to start the database. Run with 'mvn -DexternalH2=true clean test'.

Documented here but I will add the steps to the README:


The problem is that the schema will be dropped immediately after each test run so you won't see much in the database. You'll have to edit this class:


And comment out the line JPA.dropSchema(). This will of course cause problems if you run more than one test method, as each method expects a clean schema. I will have to think about how to solve this is a user-friendly way.

If you just want to see the SQL and the schema while a test runs, edit logging.properties.
Christian Bauer (56) [Avatar] Offline
Re: How access database
This is how you run a single test method with an external database:

mvn -pl examples -Dtest=org.jpwh.test.simple.CRUD#storeAndQueryItems -DexternalH2=true clean test

You will have to edit JPATest.java and disable JPA.dropSchema() to see anything in the database. I will document this better and add a disableDropSchema system property.
Christian Bauer (56) [Avatar] Offline
Re: How access database
And execute 'mvn -DskipTests=true clean install' before you run the single test and after editing JPATest.java.
JacobBosma (4) [Avatar] Offline
Re: How access database
Just one more thing needed to be changed :
HibernateSetup.java : property hibernate.hbm2ddl.auto from create-drop to create.