Wednesday, March 17, 2010

JPA 2 with Hibernate 3.5.0-CR-2

Writing this down so maybe it can help someone that wants to get started with JPA 2 with Hibernate 3.5.0-CR-2 as the underlying persistence framework.

Because you can be lost (At least I did!) to write the plumber code (e.g. maven's pom.xml,, persistence.xml etc) I have prepared a small project that demonstrates just an @OneToOne relation between a Customer and Address. I used H2 as the underlying database(my preferred embedded db of choice) but you can easily change it to use your preferred one(by editing the persistence.xml file).

Unzip the file that you can find here, edit the persistence.xml and change the 'javax.persistence.jdbc.url" property (yeap no more vendor properties!) to point to a folder in your local machine.

And then type the usual commands
mvn clean
mvn compile
mvn exec:java -Dexec.mainClass="gr.forthnet.rd.casper.jpademos.jpademo1.Main"

I am thinking of starting a series of posts as I am getting familiar with JPA 2.

Hope that helps