Hibernate 3.6 Tutorial
We will explore the basics of hibernate before we jump on to further exploration
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.
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.
In Real world applications it is natural to have composite keys to identify a row, which is combination of key columns.
This example tells about how to map one-to-one relationship using Hibernate.
Many-to-One is another relationship. Here we are describing this relationship through Employee and Dept table.
In this example we are describing one-to-many relation. There are two table one is Faculty and other is Subject.
This mapping tells about many-to-many mapping. There are two tables, one is "Customer" and other is "Policy".
Hibernate supports query via store procedure and functions. We can use store procedure in various ways.
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 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)
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
In section we'll show how to use Group by clause in criteria.