Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

1

Advanced Java
Topic: 1. Hibernate 3.0

HIBERNATE
2

Hibernate is a java package that makes it easy to work with relational database.

def:-Mapping: Copying of table to objects and objects to table is called object relational mapping.

Hibernate is an object-relational mapping (ORM) library, providing a framework for mapping an object-oriented domain model to a traditional relational database. Hibernate provides a solution to map database tables to a class.
In

other words, it supports to save objects to the database tables

Hibernate Query Language


3

Hibernate generates the SQL calls and attempts to relieve the developer from manual result set handling and object conversion.

HQL(Hibernate Query Lang):- Hibernate uses a HQL lang internally to map with the database.
HQL is similar to SQL but, can understand OOPs

ADVANTAGES OF HIBERNATE
4

Hibernate

is Robust and high in performance. Hibernate reduce the development time because it is totally follow the polymorphism ,inheritance and java collections. Hibernate is database independent. it can be used for any database. Hibernate support full object oriented query language.
Object

relational mapping is one of the important feature of hibernate. Hibernate provide a important feature of automatic key generation. i.e. automatic primary key generation.

Hibernate API
5

org.hibernate package is called as Hibernate API It contains two interfaces:


org.hibernate.SessionFactory

interface org.hibernate.Session interface

SessionFactory opens a session, it should be stored in Session object and Session obj will save the data in database. Recommended usage: Create one SessioFactory for one application, create multiple sessions for each user.

Now

we create a mapping file. The mapping file explains Hibernate which field in the class is mapped to which field of the database.

Mapping is used to insert ,update, select data to the table. Example: <hibernate-mapping package=myapck"> <class name="Demo" table="Emp"> <id name="id" column="fid" type="java.lang.Integer"> <generator class="sequence"> <param name="sequence">public Demo_fid_seq</param> </generator> </id> <property name="title" column="ftitle" type="java.lang.String" /> </class> </hibernate-mapping>

You might also like