Spring Experiences - 2 (Power of Hibernate)
It's time to generate java mapping classes to our DB. Hibernate is really a very powerful ORM framework. On top of that, it offers plethora of tools, IDE integration plugins, especially if you are developing on Eclipse.
So here's excellent description of hibernate tools installation:
http://www.hibernate.org/hib_docs/tools/reference/en/html_single/
Please refer it. For our project, we need not install anything related to jboss. Our project will be quite simple, light-weight. We will have Spring to wire all our objects and Jetty can be configured as web-application server, our object container.
At this point I assume, referring above link, you all have installed hibernate tools. It further explains how-to 'reverse engineer code'. It's quite simple. If you are using MySql, you might need to download mysql-jdbc-connector and include it your classpath (simply import it in lib directory - A directory under your project-root containing all jars). When you would opt for reverse engineer, you can specify what all you would like to be reverse engineered or exported (these options are under the Export tab). I prefer only .java domain files, hbm.xml and html documentation. We would code our own DAOs as per needed functionality. In later post you would see, how Spring wonderfully harnesses hibernate's functionality and helps building extensive, scalable and rapid application development.
Once you have the reverse-engineered code generated, there's 1 catch for MySql (atleast till date, the current version of of hibernate tools) . All .hbm.xml files you might find this string being added:
catalog="databaseName"
this is a BUG! It happens for MySql, not sure for other DBs. But thats the only bug, rest everything works like a charm. And fix to this problem is simple, remove the string from all your .hbm.xml files. Further more if you are on *unix based platform (I am on FreeBsd), I can help you better ...
simply use script to eliminate the string. On command line you can check it real quick as:
cat table.hbm.xml sed 's/ catalog = "databaseName"//' > table_1.hbm.xml
Hmmmm.... all right, now we have all java classes, next what? Isn't this article about Spring? Ofcourse, it definitely is about Spring. Spring does support + enhances use of various other technologies in a amazing fashion. As per our early decision, application being data-centric, we started from database. Now we are well established with the back-end DB layer. It's time to further build access logic and actual business logic. In my next post, we would start building code and wiring it with Spring.
So here's excellent description of hibernate tools installation:
http://www.hibernate.org/hib_docs/tools/reference/en/html_single/
Please refer it. For our project, we need not install anything related to jboss. Our project will be quite simple, light-weight. We will have Spring to wire all our objects and Jetty can be configured as web-application server, our object container.
At this point I assume, referring above link, you all have installed hibernate tools. It further explains how-to 'reverse engineer code'. It's quite simple. If you are using MySql, you might need to download mysql-jdbc-connector and include it your classpath (simply import it in lib directory - A directory under your project-root containing all jars). When you would opt for reverse engineer, you can specify what all you would like to be reverse engineered or exported (these options are under the Export tab). I prefer only .java domain files, hbm.xml and html documentation. We would code our own DAOs as per needed functionality. In later post you would see, how Spring wonderfully harnesses hibernate's functionality and helps building extensive, scalable and rapid application development.
Once you have the reverse-engineered code generated, there's 1 catch for MySql (atleast till date, the current version of of hibernate tools) . All .hbm.xml files you might find this string being added:
catalog="databaseName"
this is a BUG! It happens for MySql, not sure for other DBs. But thats the only bug, rest everything works like a charm. And fix to this problem is simple, remove the string from all your .hbm.xml files. Further more if you are on *unix based platform (I am on FreeBsd), I can help you better ...
simply use script to eliminate the string. On command line you can check it real quick as:
cat table.hbm.xml sed 's/ catalog = "databaseName"//' > table_1.hbm.xml
Hmmmm.... all right, now we have all java classes, next what? Isn't this article about Spring? Ofcourse, it definitely is about Spring. Spring does support + enhances use of various other technologies in a amazing fashion. As per our early decision, application being data-centric, we started from database. Now we are well established with the back-end DB layer. It's time to further build access logic and actual business logic. In my next post, we would start building code and wiring it with Spring.
0 Comments:
Post a Comment
<< Home