Now, lets talk about combining hibernate persistence framework and Spring framework. As you see from previous post, that Spring JDBC still use SQL query to access data objects in database. All that you need are:
1. Eclipse as IDE
2. MySQL 5 as Database
We also need other libraries such as:
1. Spring Framework
2. Hibernate-3.*
3. MySQL-connector-java-5.*
4. Jakarta-commons
5. X-Doclet-1.*
Create a java project in Eclipse named SpringHibernateExample. Create a new folder named lib. It is used to place our libraries. Move all libraries above to folder lib. So in the lib folder, there are 5 folders inside. Also add a properties file in the lib folder named lib.properties. This is an example, my lib.properties. It show my libraries configuration. Make it in your own. Also configure build path our project into these libraries.
lib.properties
In source folder make java package named com.ndung.model and com.ndung.main. We will place our POJOs in com.ndung.model and main file in com.ndung.main. Create java classes in com.ndung.model named User.java and UserDaoHibernate.java as data access object to database. Also make a xml file named myconfig.xml and a properties file named hibernate.properties in our project source folder. In other side, create java main class named Main.java in com.ndung.main.
User.java
UserDaoHibernate.java
myconfig.xml
hibernate.properties
Main.java
As usually we will run our project by using Ant. Create two xml files named properties.xml and build.xml.
properties.xml
build.xml
Wednesday, August 20, 2008
Spring-Hibernate Hands On
Posted by L.P. Manik at 1:54 PM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment