Hibernate is an object/relational mapping tool for Java environments. What does it mean the term object/relational mapping? simply a technique of mapping a data representation from an object model to a relational data model with a SQL-based schema.
Hibernate tutorial with Eclipse
For this tutorial we'll use Hibernate 3.5.6 GA which you can download here:
The tutorial will be built using Eclipse Enterprise, anyway, since we'll create the Project as simple java project you can easily adapt it on any other IDE. Ok, at fist let's create a new Java project. We'll name it "Hibernate tutorial".
Next step is adding a Java class which will be mapped on the DB. We'll create class com.sample.Person :
Class is a sample JavaBean with properties and getters/setters
Hibernate needs to know how to load and store objects of the persistent class. This is where the Hibernate mapping file comes into play. The mapping file tells Hibernate what table in the database it has to access, and what columns in that table it should use.
Create a file named Person.hbm.xml in the same package/folder of your JavaBean Person.
The id element is the declaration of the identifier property, name="id" declares the name of the Java property - The column attribute tells Hibernate which column of the PERSON table we use for this primary key.
The nested generator element specifies the identifier generation strategy: in this case we used native, which picks the best strategy depending on the configured database (dialect).
The fields are enlist as "property". Notice the column attribute is added on every property even if this can be skipped if java property = database field.