Sunday, July 12, 2009

Hibernate querying and iteration using JSTL


1.If a query return a single raw with data from mulitple tables
(unique result with mulitple objects in-hibernate),
it returns array of Entity Objects.
A[0]
A[n]
....

2.If a query return multiple raws with data from mulitple tabels
it return List of Array objects.
L[0] ---
|+--- A[0]...A[m]
L[n] ---
|+--- A[0]...A[m]
.....

Code for situation 1

SQLQuery query = session.createSQLQuery(sql);
query.addEntity("person", Person.class);
query.addEntity("specializations", Entity.Specializations.class);

Object obj = query.uniqueResult();
// obj is an array
//A[0] will be a "person" and A[1] will be a "specializations" Object

View using JSTL

${objectArray[0].salutationText}. ${objectArray[0].nameWithInitials}
${objectArray[1].specializationText}



Code for situation 2

SQLQuery query = session.createSQLQuery(sql);
query.addEntity("session", Entity.Session.class);
query.addEntity("person", Person.class);

list = query.list();
// this return List of Arrays
// where L[n] A[0] -- "session" , A[1] -- "person"

Iterate using JSTL


${p[0].sessionId}
${p[0].sessionDate}
${p[1].name}
${p[1].address}





Share Article : Hibernate querying and iteration using JSTL
Share/Save/Bookmark

0 comments:

Post a Comment