JacobBosma (4) [Avatar] Offline
#1
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
#2
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:

http://jpwh.org/examples/jpwh2/jpwh-2e-examples-20130506/environment/src/main/java/org/jpwh/env/TransactionManagerSetup.java

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:

http://jpwh.org/examples/jpwh2/jpwh-2e-examples-20130506/environment/src/main/java/org/jpwh/env/JPATest.java

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
#3
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
#4
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
#5
Re: How access database
Perfect.
Just one more thing needed to be changed :
HibernateSetup.java : property hibernate.hbm2ddl.auto from create-drop to create.