Increment with hibernate generator

This is continuation of my previous post.

We discussed with different type of generators for primary keys and we have seen an example with ‘assigned’ previously. We can see ‘generator’ in this post.

RoseIndia says we shouldnt use this in clustered invironment.

Create a table using the following structure.

BOOK-table structure

BOOK-table structure

Let your DTO be like this
package hib;

public class Book {
private long bookID;
private String bookName;
public long getBookID() {
return bookID;
}
public void setBookID(long bookID) {
this.bookID = bookID;
}
public String getBookName() {
Continue Reading

Show light on Hibernate mapping file

This is in continuation of my previous post.

Lets take the hibernate mapping file and get to the tags used in that file.

<?xml version=”1.0″?>
<!DOCTYPE hibernate-mapping PUBLIC
“-//Hibernate/Hibernate Mapping DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”>

<hibernate-mapping>
<class name=”hib.Contact” table=”CONTACT”>
<id name=”id” type=”long” column=”ID” >
<generator/>
</id>

<property name=”firstName”>
<column name=”FIRSTNAME” />
</property>
<property name=”lastName”>
<column name=”LASTNAME”/>
</property>
<property name=”email”>
<column name=”EMAIL”/>
</property>
</class>
</hibernate-mapping>

We could see some XML tags tries forms this mapping. Their explanations are given below.
hibernate-mapping
Root element of this mapping
class
maps the java class and SQL table
id
This will handle the primary key constraint. In addition this is … Continue Reading

Hibernate demo

hibernate

hibernate

This post will help you to setup the environment to write your first hello world program with Hibernate!

  1. Get the hibernate distribution from their website. (as of now, I have hibernate-distribution-3.3.2.GA-dist.zip with me)
  2. Download the jars for commons-logging, asm and JDBC driver for your database.
  3. Start a java project in eclipse.
  4. Add all jars in hibernate distribution and other libraries mentioned in step 2.
  5. Prepare your hibernate configuration file
  6. Prepare your Data Transfer Object (DTO) and SQL table
  7. Prepare your hibernate mapping file for your DTO
  8. Start JDBC calls.

Library files needed

Almost all jars are being distributed. … Continue Reading