Spring 3.0 tutorial – part 6 (with Hibernate & HSQLDB)

This is a very simple Spring tutorial with Hibernate and HSQLDB. This assumes that you have gone through the tutorials

1) Setting up Java, Maven, and Eclipse
2) The “Course” table is created as per the tutorials “SQL Tutorial with HSQLDB” and “JDBC Tutorial with HSQLDB”
3) Spring 3.0 tutorial part 1 to part 3.

The key artifacts are as shown below.

spring-hibernate-tut-1

Step 1: pom.xml file with spring, hibernate, HSQLDB, and Apache datasource dependendencies. You can try using different versions (i.e. latest).

Spring Architecture

Spring Architecture

Step 2: The “Course” domain object that maps to the Course database table that we created in the “SQL and HSQLDB” tutorial.

Step 3: Define the DAO layer Java interface and implementation for Course.

Step 4: Define the Service layer Java interface and implementation for Course.

Note: Note that “CoursDaoImpl” need to be injected via Spring into the “CourseServiceImpl”.

Step 5: The name/value pair with database and hibernate properteis.

conf/db.properties

# jdbc.X
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:hsql://localhost/mytestdb
jdbc.user=SA
jdbc.pass=
# hibernate.X
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=

Step 6: The Spring context XML file that wires up dependencies.

conf/courseApplicationContext.xml

Step 7: Finally, bootstrap the “courseApplicationContext.xml” via the App.java with the main method to execute this stand alone.

Step 8: Make sure that your HSQLDB server is running as explained in “SQL and HSQLDB” tutorial with the “Course” table.

sql-hsql-7

sql-hsql-3

Output:

Note: You can see the course details read from the “Course” database.


Java developer & architect Q&As

Java developers Q&As

Top