Monday, October 01, 2007

Setup JBoss Hibernate and MySQL..even your grandma could do it!

I have been reading Gavin King's blog last week while he was trying to provide some arguments regarding Hibernate's evolution towards simplicity (Hibernate ver 3.x). There was some kind of comparison by someone else regarding a new ORM solution and how it is less complicated even to setup comparing to Hibernate.

Well for sure if you go through Hibernate's revisions, setup config files etc. etc it was an issue in the past especially for non experienced developers, though now in its latest revision things have been very very simple and straight forward. Yes you may still argue that it is a huge technology beast and needs time to master, some people still using it the wrong way..but actually if you think about it ..I have not met lots of Hibernate Master's out there. We are all keep working and reading and reading and exchanging views trying to grasp all the details. It's the only way to go! An ORM for sure its not a simple thing to master - even the actuall problem an ORM tries to solve is not simple.

We must all agree though that Hibernate is one of the best (if not the best) Enterprise level ORM, most of us have been using it for years and yes it is working..really it is!

So let's take the simplest path, we want Hibernate with an J2EE application server (I am an EJB guy dont expect at the moment lots of Spring stuff - working on it!) . I am also a huge supporter of EJB3 (yes working on EJB2.1 it's not as pleasant as working on the latest spec).So in 2 minutes you will be ready!

So..the steps!

1. Download the JBoss Application Server from here - it has Hibernate libraries already 'copied' on his internal folders , currently version 4.2.1 has Hibernate v3.2.4.sp1_cp01 according to the notes .

2. Make sure you have installed properly your database, in my case it is MySQL. Dont forget to set up the appropriate privilidges and sort out the admin accounts and the user accounts.

3. Create a JCA datasource configuration, that involes a very simple file that you need to copy in your /server/default/deploy/ folder. Here it is!


All the related info here!

4. Provide the file to glue the JCA datasource and the Hibernate Engine. It is know as the
persistence.xml aka Persistence Unit (it is highlighted in G.King's post as well).We usually package it under our EJB jars (in a EJB app scenario) under /META-INF/




4.1 make sure you write the appropriate jta-datasource field (the same name with the datasourece must apply).

4.2 I have followed the simplest path - very usefull for rapid application development and prototyping I have set Hibernates HBM2DDl setting to update, so I am leaving Hibernate to resolve all the schema changes - that come through the implementation of my EJB entity beans (in my case).

5. You are ready..I mean even your grandma could do it! You are ready to write your EJB3 entity beans with annotations and no hbm's , no other configs , nothing.. let hibernate resolve db schema changes on the first rounds of initial development!

No comments:

Post a Comment