You are on page 1of 69

Unit 2 : OR Mapping Relations and Inheritance

ER/CORP/CRS/<CourseCode>/003 Confidential 2008, Infosys Technologies Ltd.

Hibernate Mapping Files


Object Relational mapping defined in XML document Mapping documents are readable and hand-editable Mapping language is java-centric, mapping constructed around persistent classes not table declaration Can use tool like XDoclet and annotation Define identifier generation, properties, object relationship ..
Infosys Technologies Ltd.

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Mapping relationships
Types one-to-one Either end can be the owner (only one) many-to-one Many end must be the owner one-to-many Many end must be the owner many-to-many Either end can be owner

Infosys Technologies Ltd.

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

One to One Relationship


Expresses a relationship between two classes where each instance of the first class is mapped to a single instance of the second class or vice versa One to One relationship can be implemented in the database in different two ways Giving each of the respective tables the same primary key values Using foreign key constraint from one table onto a Infosys Technologies Ltd. unique identifier column of the other
USER
PK Id userName Email PK Id email FK- userId

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

One-To-One Unidirectional
package org.demo; class Person { private int personId; .. private Email address; ... } package org.demo; class Email { private int pk_id; ... }
Infosys Technologies Ltd.

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

The Mapping File


<class name="org.demo.Person" table="PERSON"> ... <many-to-one name="address" column=EMAIL_ID" class="org.demo.Email" cascade="save-update" unique="true"/> ...... </class> //ADDRESS Mapping <class name="org.demo.Address" table="ADDRESS"> ... </class>
2008, Infosys Technologies Ltd.

Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

One-to-Many and Many-to-one Association Relationship


Representation By foreign key, with no additional constraints Link table by maintaining foreign key into each of associated tables Unique constraint to be specified on the one side of relation (one to many) else it will be many to many
Infosys Technologies Ltd. USER PK Id userName USER_Email

Email
PK Id email

PK,FK userId
PK,FK emailId

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

One-To-Many Relationship
<set> <bag> <list> <array>

Infosys Technologies Ltd.

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

One to Many relationship: Creating Object Instance


Country has many states public class Country { private Long countryid; private String name; // Country has one-to-many relationship with States private Set states; } Infosys Technologies Ltd. public class State { private Long stateid; private String name; }
2008, Infosys Technologies Ltd.
Confidential 10 We enable you to leverage knowledge anytime, anywhere!

1.One to Many :Using <set>


<class name=Country" table=country"> <id name=countryid" column=countryid" type="long" unsaved-value="null"> <generator class=assigned"/> </id> <property name="name" column=countryname type="string" length="100"/> <set name="states" cascade="all"> Ltd. Infosys Technologies <key column=country_id"/> <one-to-many class=State"/> </set> </class>
2008, Infosys Technologies Ltd.
Confidential 11 We enable you to leverage knowledge anytime, anywhere!

One to Many : Using Set in Domain Class


Country has many states Country country=new Country(); country.setName(India"); country.setStates(new HashSet()); country.getStates().add(new State(Maharashtra)); country. getStates().add(new State(Gujarat)); Infosys Technologies Ltd. session.saveOrUpdate(country);

12 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

One to Many relationship :List


public class Author{ private int id; private String name; private List books; public void setBooks(List l) { bools = l; } public List getBooks() { Infosys Technologies Ltd. return books; } // ...
13 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

2. One to Many relationship: <list>


Author has written many books <class name=Author" table="grouptable"> <id name="id" unsaved-value="0"> <generator class=increment /> </id> <list name=books" cascade="all"> <key column=author_id" /> <index column="idx" Technologies Ltd. /> Infosys <one-to-many class=Books" /> </list> <property name="name" type="string" /> </class>
14 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

One to Many relationship :<array>


public class Author{ private int id; private String name; private Book[ ] books; public void setBooks(List l) { bools = l; } public List getBooks() { Infosys Technologies Ltd. return books; } // ...
15 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

3. One to Many relationship: <array>


<class name=Author" table="grouptable"> <id name="id" unsaved-value="0"> <generator class="increment"/> </id> <array name=books" cascade="all"> <key column=author_id"/> <index column="idx"/> Infosys Technologies Ltd. <one-to-many class=Book"/> </array> <property name="name" type="string"/> </class>
16 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

One to Many relationship :Object Instance


ArrayList list = new ArrayList(); list.add(new Book(Java")); list.add(new Book("Servlets")); list.add(new Book("JSP")); Author sp = new Author(Author1); sp.setBooks(list);
Infosys Technologies Ltd.

17 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

4. One to Many relationship: <bag>


<class name=Country" table=country"> <id name=countryid" column=countryid" type="long" unsaved-value="null"> <generator class=assigned"/> </id> <property name="name" column=countryname type="string" length="100"/> <bag name="states" cascade="all"> Ltd. Infosys Technologies <key column=country_id"/> <one-to-many class=State"/> </bag> </class>
18 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

Many to Many relationship:


Event has many speakers

public class EventManyToMany { private Long id; private String name; private int duration; private Set speakers; public void setSpeakers(Set speakers) { Infosys Technologies Ltd. this.speakers = speakers; } public Set getSpeakers() { return speakers; } We enable you to leverage knowledge 19 Confidential 2008, Infosys Technologies Ltd. anytime, anywhere! // ...

Many to Many relationship:


A speaker speaks in many events public class SpeakerManyToMany { private Long id; private String first_Name; private String last_Name; private Set events; public Set getEvents() { Infosys Technologies Ltd. return this.events; } public void setEvents(Set events) { this.events = events; }
20 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

Many to Many relationship One Event has many speakers and one speakers participates in many events <class name="SpeakerManyToMany table="m_speakers"> <id name="id" column="uid" type="long"> <generator class="increment"/> </id> <property name="firstName" type="string" length="20"/> <property name="lastName" type="string" length="20"/> Infosys Technologies Ltd. <set name="events" table="event_speakers cascade="all"> <key column="speakers_id"/> <many-to-many class="EventManyToMany"/> </set></class>
21 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

Mapping Object Inheritance


22 Confidential 2008, Infosys Technologies Ltd.

Inheritance
Three strategies One table per class One table per subclass One table per concrete class

Infosys Technologies Ltd.

23 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Example
class Payment payment_id amount class CreditCardPayment creditcard_type

Infosys Technologies Ltd.

2008, Infosys Technologies Ltd.

Confidential

24

We enable you to leverage knowledge anytime, anywhere!

One table per class hierarchy


One table for the whole class hierarchy A discriminator column is a key to uniquely identify the base type Advantages This hierarchy offers the best performance even for in the deep hierarchy since single select may suffice Disadvantages hierarchy require column to Changes to members of theInfosys Technologies Ltd. be altered, added or removed from the table

2008, Infosys Technologies Ltd. 25 Confidential

We enable you to leverage knowledge anytime, anywhere!

One Table per Class Hierarchy


How to define the mapping Use <subclass> element and extend superclass using extends define discriminator-value attributes

Infosys Technologies Ltd.

2008, Infosys Technologies Ltd. 26 Confidential

We enable you to leverage knowledge anytime, anywhere!

One table per Class Hierarchy


<hibernate-mapping> <subclass name=CreditCardPayment extends=Payment" discriminator-value=CreditCard"> <property name=creditcardtype" type="string" /> </subclass> </hibernate-mapping>
Infosys Technologies Ltd.

2008, Infosys Technologies Ltd.

Confidential

27

We enable you to leverage knowledge anytime, anywhere!

One Table per Subclass


One table for each subclass Foreign key relationship exists between common table and subclass tables Advantages Using this hierarchy, does not require complex changes to the database schema when a single parent class is modified It works well with shallow hierarchy Infosys Technologies Ltd. Disadvantages As the hierarchy, it may result in poor performance The number of joins required to construct a subclass class also grows
2008, Infosys Technologies Ltd. 28 Confidential
We enable you to leverage knowledge anytime, anywhere!

One Table per Subclass


Use <joined-subclass> element and extends attributes that defines the superclass

Infosys Technologies Ltd.

2008, Infosys Technologies Ltd. 29 Confidential

We enable you to leverage knowledge anytime, anywhere!

One Table per Subclass


<hibernate-mapping> <joined-subclass name=CreditCardPayment" extends=Payment> <key column="id" /> <property name=" creditcardtype" type="string" /> </joined-subclass> </hibernate-mapping>
Infosys Technologies Ltd.

2008, Infosys Technologies Ltd.

Confidential

30

We enable you to leverage knowledge anytime, anywhere!

Mapping Inheritance:1 Table for ConcreteClass


Map each of the concrete classes as a normal persistent class Advantages It is easiest to implement Disadvantages Data that belongs to a parent class is scattered across a number of subclass tables, which represents concrete classes Infosys Technologies Ltd. A query couched in terms of parent class is likely to cause a large number of select operations

2008, Infosys Technologies Ltd. 31 Confidential

We enable you to leverage knowledge anytime, anywhere!

Mapping Inheritance:One Table for Concrete Class


Changes to a parent class is reflected to large number of tables This hierarchy is not recommended for most cases

Infosys Technologies Ltd.

2008, Infosys Technologies Ltd.

Confidential

32

We enable you to leverage knowledge anytime, anywhere!

One Table per Concrete Class


The mapping of the subclass repeats the properties of the parent class

Infosys Technologies Ltd.

2008, Infosys Technologies Ltd. 33 Confidential

We enable you to leverage knowledge anytime, anywhere!

One Table per Concrete Class


<hibernate-mapping> <class name=Payment> <id name=payment_id" type="integer" unsaved-value="0"> <generator class="increment"/> </id> <property name=amount"/> </class> <class name=CreditCardPayment> <id name=payment_id" type="integer" unsaved-value="0"> <generator class="increment"/> Infosys Technologies Ltd. </id> <property name=amount"/> <property name=creditcardtype"/> </class> </hibernate-mapping>
2008, Infosys Technologies Ltd.
Confidential 34 We enable you to leverage knowledge anytime, anywhere!

Infosys Technologies Ltd.

QUERY FACILITY IN HIBERNATE


2008, Infosys Technologies Ltd.
Confidential 35 We enable you to leverage knowledge anytime, anywhere!

Query Facility in Hibernate


We can get data from the database using hibernate in 3 different ways 1.Criteria Query 2.HQL 3.Native SQL

Infosys Technologies Ltd.

2008, Infosys Technologies Ltd. 36 Confidential

We enable you to leverage knowledge anytime, anywhere!

Criteria Query API


Infosys Technologies Ltd.

37 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Criteria Query API Queries can be constructed using a set of Java Objects instead of query language Lets you assemble nested, structured query expressions in Java programming language Compile time syntax checking possible Polymorphic behavior is supported Eg:get instances of X & subclass(X) Supports Query By Example (QBE) Querying by providingInfosys Technologies Ltd. object which an example contain properties that has to be retrieved Supports aggregation methods (from Hibernate 3 onwards)

38 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Creating Criteria object


Steps for a Simple Query 1.Create Criteria object(org.hibernate.Criteria) via createCriteria() factory method of the Session 2.Pass persistent object's class or the entity name to the createCriteria() method 3Call list() method of the Criteria object Eg: 1.Get all instances of Employee class and its subclasses Infosys Technologies Ltd. Criteria crit = sess.createCriteria(Employee.class); List results = crit.list();

39 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Selecting Fewer Rows using :-Restrictions


To the Criteria query object add restrictions with add() method The add() method takes an Criterion object that represents an individual restriction Eg:2// Retrieve Employee data whose name has a pattern Criteria crit = session.createCriteria(Employee.class); Criterion c= Restrictions.eq(name, Infy) Infosys Technologies Ltd. crit.add(c); List results = crit.list(); You can have any number of restriction for a Criteria query

2008, Infosys Technologies Ltd.

Confidential

40

We enable you to leverage knowledge anytime, anywhere!

Methods of Restriction Class


Restrictions.eq(name, Infy) Restrictions.ne(name, NoName) Restrictions.like(name, Sa%) Restrictions.ilike(name, sa%) Restrictions.isNull(name); Restrictions.gt(price,new Double(30.0)) Restrictions.between(age, new Integer(2), new Infosys Technologies Ltd. Integer(10))

41 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Logical Grouping - Restrictions


Eg-3 :Retrieve Employee objects whose name has a pattern and whose exp is 10 or null List people = sess.createCriteria(Employee.class) .add( Restrictions.like("name", R%") ) .add( Restrictions.or( Restrictions.eq( exp", new Integer(10) ), Restrictions.isNull(exp)) ) Infosys Technologies Ltd. .list();

2008, Infosys Technologies Ltd.

Confidential

42

We enable you to leverage knowledge anytime, anywhere!

Pagination through ResultSet


Hibernate handles the pagination Retrieving fixed number of objects Two methods of Criteria class setFirstResult() To set the first row in the result setMaxResults() The number of rows to be retrieved Eg:4 Using pagination Infosys Technologies Ltd. Criteria crit = sess.createCriteria(Employee.class); crit.setFirstResult(2); crit.setMaxResults(50); List results = crit.list();
43 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

Aggregate Functions
avg(String propertyName) average of a property's value count(String propertyName) number of times the given property has a value countDistinct(String propertyName) number of unique values the said property contains max(String propertyName) min(String propertyName) Infosys Technologies Ltd. sum(String propertyName) sum of the property values

44 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Aggregate Functions

[contd]

We can call different aggregate functions using the Projections factory class. Once the projection object is created add it to the criteria object using setProjection() method Eg:-The result will contain one object, an Integer that Holds the results of executing Avg(Salary)SQL statement Infosys Technologies Ltd. Criteria crit = sess.createCriteria(Employee.class); crit.setProjection( Projections. avg (salary) ); List results = crit.list();

2008, Infosys Technologies Ltd. 45 Confidential

We enable you to leverage knowledge anytime, anywhere!

Hibernate Query Language (HQL)


Infosys Technologies Ltd.

46 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Hibernate Query Capabilities in 3.0


Newly improved Hibernate Criteria Query API Hibernate Query Language (HQL) queries that are provided in the native SQL dialect of the database is also supported

Infosys Technologies Ltd.

47 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Hibernate Query Language (HQL)


Very similar to SQL but less verbose Understands OO concepts like inheritance, polymorphism , association, aggregation, composition Selection from, as Projection select, elements Infosys Technologies Ltd. Constraints where Associations and joinsouter join, full join, inner join, right outer join
48 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

Hibernate Query Language (HQL)


Other constructs-> aggregate functions, expressions, group by clauses, order by clauses, polymorphic selections, sub-queries
Infosys Technologies Ltd.

49 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Differences from SQL


HQL is fully object-oriented and understands notions like, polymorphism ,association and inheritance Queries are case-insensitive,but for the names of Java classes and properties

Infosys Technologies Ltd.

50 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

from clause
Return all instances of the class example.Event from example.Event

Usually don't need give the fully qualified name of the class , since auto-import is the default.
from Event = from example.Event

you can assign an alias, so that you can refer to the class in other parts of the query Technologies Ltd. Infosys
from Event as evt (evt is the alias) from Event evt (as can be omitted)

51 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Alias
Multiple classes may emerge, resulting in a Cartesian product or "cross" join. from Employee, Dependants from Formula as emp, Dependants as deps Tip : query aliases can be named using an initial lowercase so that it is consistent with Java naming standards for local variables
Infosys Technologies Ltd.

52 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Join
We may also assign aliases to elements of a collection of values or to associated entities, using a join Eg1. from Event as evt inner join evt.speakers as spk left outer join sp.venue as venue Eg:2 from Event as evt left join evt.speakers.venue as venue
Infosys Technologies Ltd.

Eg:3 from Formula form full join form.parameter param

53 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Join types supported


inner join left outer join right outer join full join (not usually useful)

Infosys Technologies Ltd.

54 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

select clause
The select clause picks which properties & objects to return in the query result set select spk from Event as evt inner join evt.speaker as spk Compact form select evt.speaker from Event evt
Infosys Technologies Ltd.

55 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

select clause
properties of any value type including the properties of component type can be returned by Queries select evt.name from Event evt where evt.name like Hib%' select cust.name.firstName from Customer as cust properties as an array of type Object[ ] and/or multiple Infosys Technologies Ltd. objects can be returned by Queries

select mother, offspr, mate.name from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr
56 2008, Infosys Technologies Ltd. Confidential We enable you to leverage knowledge anytime, anywhere!

where clause
The list of instances returned can be narrowed by the Where clause. you may refer to properties by name ,If no alias exists from Event where name=Hibernate Session' use a qualified property name ,If there is an alias : from Event as evt where evt.name= Hibernate Session'
Infosys Technologies Ltd.

57 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

where clause

[cont]

Return all instances of Event for which there exists an instance of Speaker with a id property equal to the spkid property of the Event select evt from Event evt, Speaker spk where evt.spkid = spk.id Compound path expressions make the where clause Infosys Technologies Ltd. extremely powerful. from Event evt where evt.speaker.name is not null

58 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Native SQL Query


Native SQL is SQL in the native format for the database you are connected to, to performs operations like create, update, delete and select. Use createSQLQuery() method of session Object to pass the query string. It returns a SQLQuery object Invoke the list() to get the data from the selected database table
Infosys Technologies Ltd.

2008, Infosys Technologies Ltd. 59 Confidential

We enable you to leverage knowledge anytime, anywhere!

Native SQL Query


// Build SQL query
{

[contd]

System.out.println("\n---Using SQL query with where clause..."); String sql = "select * from Supplier supplier"; SQLQuery query = session.createSQLQuery(sql); query.addEntity("supplier", Supplier.class); List results = query.list(); displaySupplierList(results);

}
Infosys Technologies Ltd.

2008, Infosys Technologies Ltd. 60 Confidential

We enable you to leverage knowledge anytime, anywhere!

Demo Program
Table Name:EMPOLOYEE

Entity class Name :Employee

ID
1001

name
John

salary joining_date
10000 12-jan-2009

Infosys Technologies Ltd.


1002 Tommy 20000 13-mar-2008

1003

Angel

23000

14-jun-2008

1004

Joy

22000

23-apr-2007

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Program to find out the lowest salary amount from the table (Aggregate Function)
package demo; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration;

public class HibernateHQLMinFunction {


public static void main(String[] args) { // TODO Auto-generated method stub Session sess = null; Infosys Technologies Ltd. try { SessionFactory sf = new Configuration().configure().buildSessionFactory(); sess = sf.openSession();

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Program to find out the lowest salary amount from the table (Aggregate Function) [contd]
String SQL_QUERY = "select min (salary) from Employee emp"; Query query = sess.createQuery(SQL_QUERY); List list = query.list();
System.out.println("Min Salary Amount: " + list.get(0));

} catch(Exception e){ System.out.println(e.getMessage()); } Infosys Technologies Ltd. }

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Program to find out the lowest salary amount from the table (Aggregate Function) [contd]
Output: Min Salary Amount: 10000

Infosys Technologies Ltd.

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Demo 2: Select HQL Example package demo;; import org.hibernate.Session; import org.hibernate.*; import org.hibernate.cfg.*; import java.util.*; public class SelectHQLExample { public static void main(String[] args) { Session session = null; try{ Infosys Technologies Ltd.
// prepare hibernate for use after reading the hibernate.cfg.xml

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession();


2008, Infosys Technologies Ltd.
Confidential We enable you to leverage knowledge anytime, anywhere!

Demo 2: Select HQL Example [contd]


//Using from Clause String SQL_QUERY ="from Employee emp"; Query query = session.createQuery(SQL_QUERY); for(Iterator it=query.iterate();it.hasNext();)

{ Employee emp=(Employee)it.next(); System.out.println("ID: " + emp.getId()); System.out.println("First Name: " + emp.getName()); Infosys Technologies Ltd. } session.close(); } catch(Exception e){ System.out.println(e.getMessage()); }finally{ }}}
2008, Infosys Technologies Ltd.
Confidential We enable you to leverage knowledge anytime, anywhere!

Demo 3:Select HQL program->returns an array of Object


package demo import org.hibernate.Session; import org.hibernate.*; import org.hibernate.cfg.*; import java.util.*; public class SelectClauseExample { public static void main(String[] args) { Session session = null; Infosys Technologies Ltd. try{ // prepare hibernate for use after reading the hibernate.cfg.xml SessionFactory sessionFactory = new

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Demo 3:Select HQL program->returns an array of Object [contd]


Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); //Create Select Clause HQL String SQL_QUERY ="Select emp.id,emp.name," + emp.salary,emp.joining _date from Employee emp"; Query query = session.createQuery(SQL_QUERY); for(Iterator it=query.iterate();it.hasNext();){ Object[] row = (Object[]) it.next(); System.out.println("ID: " + row[0]); System.out.println("Name: " + row[1]); Technologies Ltd. Infosys System.out.println("Amount: " + row[2]); } session.close(); }catch(Exception e){ System.out.println(e.getMessage()); }finally{} }}

2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

Summary
Introduction- Introduction to ORM & Hibernate Hibernate Architecture and Framework Hibernate Instance States ,Lifecycle Operation Hibernate Configurations Primary Key Generation, Composite Key, Hibernate Data Types OR Mapping-Relations and Inheritance Infosys Technologies Ltd. Criteria Query API, HQL & native SQL

2008, Infosys Technologies Ltd. 69 Confidential

We enable you to leverage knowledge anytime, anywhere!

Thank You
Infosys Technologies Ltd.

70 2008, Infosys Technologies Ltd.

Confidential

We enable you to leverage knowledge anytime, anywhere!

You might also like