A RHS Hibernate
A RHS Hibernate
COLLAGE OF
ENGINEERING AND
TECHNOLOGY
MADE BY:
1. KHUSHBU GAJERA(160060107011)
2. ANKITA PANDEY (160060107037)
3. RAHUL SALIYA (160060107051)
4. SNEHA PATEL (140060107044)
Table of Contents
1 What is Hibernate
2 Hibernate Architecture
Granularity
• Sometimes you will have an object model, which has more classes
than the number of corresponding tables in the database.
Inheritance
• RDBMSs do not define anything similar to Inheritance, which is a
natural paradigm in object-oriented programming languages.
Identity
• An RDBMS defines exactly one notion of 'sameness': the primary key.
Java, however, defines both object identity (a==b) and object equality
(a.equals(b)).
Associations
Object-oriented languages represent associations using object references
whereas an RDBMS represents an association as a foreign key column.
Navigation
The ways you access objects in Java and in RDBMS are fundamentally
different.
Tier Overview
Browser Business Database
or App Presentation Database
logic connection
SessionFactory Object
Configuration object is used to create a SessionFactory object
which in turn configures Hibernate for the application using the
supplied configuration file and allows for a Session object to be
instantiated. You would need one SessionFactory object per
database using a separate configuration file. So, if you are using
multiple databases, then you would have to create multiple
SessionFactory objects.
Session Object
A Session is used to get a physical connection with a
database. The Session object is lightweight and designed to
be instantiated each time an interaction is needed with the
database. Persistent objects are saved and retrieved
through a Session object.
Transaction Object
A Transaction represents a unit of work with the
database and most of the RDBMS supports
transaction functionality. Transactions in Hibernate
are handled by an underlying transaction manager
and transaction (from JDBC or JTA). This is an
optional object
Query Object
Query objects use SQL or Hibernate Query Language (HQL)
string to retrieve data from the database and create
objects. A Query instance is used to bind query parameters,
limit the number of results returned by the query, and
finally to execute the query.
Hibernate Configuration
Hibernate requires to know in advance — where to find the
mapping information that defines how your Java classes relate
to the database tables. Hibernate also requires a set of
configuration settings related to database and other related
parameters. All such information is usually supplied as a
standard Java properties file called hibernate.properties, or
as an XML file named hibernate.cfg.xml.
hibernate.cfg.xml
<?xml version = "1.0" encoding = "utf-8"?> Prerequisites
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> • testdb database
<hibernate-configuration> • test user
<session-factory>
<property name = "hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name = "hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name = "hibernate.connection.url">
jdbc:mysql://localhost/test
</property>
<property name = "hibernate.connection.username">
root
</property
<property name = "hibernate.connection.password">
root123
</property>
<!-- List of XML mapping files -->
<mapping resource = "Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Hibernate Query Language (HQL)
Hibernate Query Language (HQL) is an object-oriented query
language, similar to SQL, but instead of operating on tables
and columns, HQL works with persistent objects and their
properties. HQL queries are translated by Hibernate into
conventional SQL queries, which in turns perform action on
database.
Differences between SQL and HQL:
• SQL is based on a relational database model whereas HQL is a
combination of object-oriented programming with relational
database concepts.
• SQL manipulates data stored in tables and modifies its rows and
columns. HQL is concerned about objects and its properties.
1
THANK YOU