Hibernate 3.6 Tutorial
We will explore the basics of hibernate before we jump on to further exploration
Steps for Writng First Hibernate Application
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.
CRUD In Hibernate
A CRUD operation deals with creating , retriving , updating and deleting from the table, in this tutorial we will see how it is done.,
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.
A component mapping deals with entities involved in has - a relationship.
Composite Key Mapping
In Real world applications it is natural to have composite keys to identify a row, which is combination of key columns.
One to One Mapping
This example tells about how to map one-to-one relationship using Hibernate.
Many to One Mapping
Many-to-One is another relationship. Here we are describing this relationship through Employee and Dept table.
One to Many Mapping
In this example we are describing one-to-many relation. There are two table one is Faculty and other is Subject.
Many to Many Mapping
This mapping tells about many-to-many mapping. There are two tables, one is "Customer" and other is "Policy".
Calling Store Procdure
Hibernate supports query via store procedure and functions. We can use store procedure in various ways.
HQL In Hibernate
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.
Named Query in Hibernane
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.
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.
Here we are using some expression in criteria. Like ename should start with 'Ra' and salary between minsal and maxsal i.e(1000,3000)
Criteria Logical Exepression
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
Group by in Criteria
In section we'll show how to use Group by clause in criteria.
Left Outer join in hibernate
Here we are defining left-outer join between customer and policy tables based on customer_id.