Hibernate 3.6 Tutorial

AddThis Social Bookmark Button

We will explore  the basics of hibernate before we jump on to further exploration

AddThis Social Bookmark Button

Objective: Suppose we have a class Employee having properties eno,ename,sal,job,deptno. We want to persists this class/object to databse table employee1000.

AddThis Social Bookmark Button

A CRUD operation deals with creating , retriving , updating and deleting from the table, in this tutorial we will see how it is done.,

AddThis Social Bookmark Button

Hibernate provides advanced features, which can let your classes map even if they are in relationship like  composition and inheritance. We discussed composition last tutorial. Joined-subclass is one of the way for achieving inheritance.

AddThis Social Bookmark Button

A component mapping deals with entities involved in has - a relationship.

AddThis Social Bookmark Button

In Real world applications it is natural to  have composite keys  to identify a row, which is combination of key  columns.

AddThis Social Bookmark Button

This example tells about how to map one-to-one relationship using Hibernate.

AddThis Social Bookmark Button

Many-to-One is another relationship. Here we are describing this relationship through Employee and Dept table.

AddThis Social Bookmark Button

In this example we are describing one-to-many relation. There are two table one is Faculty and other is Subject.

AddThis Social Bookmark Button

This mapping tells about many-to-many mapping. There are two tables, one is "Customer" and other is "Policy".

AddThis Social Bookmark Button

Hibernate supports query via store procedure and functions. We can use store procedure in various ways.

AddThis Social Bookmark Button

Hql is just like sql but it is fully object oriented. Insteade of table name we have to write class neme here. And main difference is inheritance,polymerphism all object oriented properties we can define here.

AddThis Social Bookmark Button

Named querey is a concept which separate the query from coding section to hbm file with a specific   name. Which we can use by calling its name. It can be reusable.  can be native sql or hql.

AddThis Social Bookmark Button

Criteria query allows us to create and execute object-oriented query. Generally it is alternative to hql. Basically those people , whose don't have sql knowledge, they can write Criteria query.

AddThis Social Bookmark Button

Here we are using some expression in criteria. Like ename should start with 'Ra' and salary between minsal and maxsal i.e(1000,3000)

AddThis Social Bookmark Button

We can add logical expression in Criteria like

Expression.eq,  Expression.isNotNull,Expression.between,Expression.like etc. In this example we have expressed this thing

AddThis Social Bookmark Button

In section we'll show how to use Group by clause in criteria.

AddThis Social Bookmark Button

Here we are defining left-outer join between customer and policy tables based on customer_id.