Wednesday, July 29, 2009

Hibernate:Do it urself

Adapted from :docs.jboss.org

1.1. Part 1 - The first Hibernate Application
For this example, we will set up a small database application that can store events we want to attend and information about the host(s) of these events.
Note
Although you can use whatever database you feel comfortable using, we will use
HSQLDB (an in-memory, Java database) to avoid describing installation/setup of any particular database servers.
1.1.1. Setup
The first thing we need to do is to set up the development environment. We will be using the "standard layout" advocated by alot of build tools such as
Maven. Maven, in particular, has a good resource describing this layout. As this tutorial is to be a web application, we will be creating and making use of src/main/java, src/main/resources and src/main/webapp directories.
We will be using Maven in this tutorial, taking advantage of its transitive dependency management capabilities as well as the ability of many IDEs to automatically set up a project for us based on the maven descriptor. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.hibernate.tutorials
hibernate-tutorial
1.0.0-SNAPSHOT
First Hibernate Tutorial


${artifactId}



org.hibernate
hibernate-core



javax.servlet
servlet-api



org.slf4j
slf4j-simple



javassist
javassist



Tip
It is not a requirement to use Maven. If you wish to use something else to build this tutoial (such as Ant), the layout will remain the same. The only change is that you will need to manually account for all the needed dependencies. If you use something like Ivy providing transitive dependency management you would still use the dependencies mentioned below. Otherwise, you'd need to grab all dependencies, both explicit and transitive, and add them to the project's classpath. If working from the Hibernate distribution bundle, this would mean hibernate3.jar, all artifacts in the lib/required directory and all files from either the lib/bytecode/cglib or lib/bytecode/javassist directory; additionally you will need both the servlet-api jar and one of the slf4j logging backends.
Save this file as pom.xml in the project root directory.

No comments:

Post a Comment