I am using the below code, the problem I am getting is: although there are 3 rows on the database with different values, I am able to see only the first row value when I iterate the result1 list.
Code:
List result1 = null;
Transaction tx = null;
try
{
Session session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
String fldrNum = (String)request.getSession().getAttribute("fldrNum");
String caseNum = (String)request.getSession().getAttribute("caseNum");
if(fldrNum!=null&&caseNum!=null)
{
int fldrNo = Integer.parseInt(fldrNum);
int caseNo = Integer.parseInt(caseNum);
SQLQuery query = session.createSQLQuery(" Select {ccg1.*} from CaseContact
as ccg1 "
+" where " +
" ccg1.folderNumber="+fldrNo+
" and ccg1.caseNumber="+caseNo+
" and ccg1.contactTypeCode in "+
" ('1', '2', '3', '4', '5')"
);
result1 = query.addEntity("ccg1",CaseContactGS.class).list();
System.out.println((result1.get(1)) instanceof CaseContactGS);
System.out.println("code:"+((CaseContactGS)(result1.get(0))).getContactTypeCode());
System.out.println("Key:"+((CaseContactGS)(result1.get(0))).getCaseContactKey());
System.out.println("code:"+((CaseContactGS)(result1.get(1))).getContactTypeCode());
System.out.println("Key:"+((CaseContactGS)(result1.get(1))).getCaseContactKey());
for( Iterator it = result1.iterator(); it.hasNext();)
{
CaseContactGS ccgObject = (CaseContactGS) it.next();
System.out.println("ID: " + ccgObject.getContactTypeCode());
System.out.println("Name: " + ccgObject.getCaseContactKey());
}
tx.commit();
}
catch (HibernateException e)
{
throw new RuntimeException(e.getMessage());
}
finally
{
HibernateSessionFactory.closeSession();
}
Displayed output:
[8/4/11 11:40:13:321 CDT] 00000035 SystemOut O Hibernate: Select ccg1.caseNumber as caseNumber0_, ccg1.CaseContact_pk as CaseCont2_9_0_, ccg1.contactTypeCode as contactT3_9_0_, ccg1.folderNumber as folderNu4_9_0_, ccg1.repPayeeName as repPayee5_9_0_, ccg1.ssn as ssn9_0_ from CaseContact as ccg1 where ccg1.folderNumber=192653902 and ccg1.caseNumber=198777140 and ccg1.contactTypeCode in ('1', '2', '3', '4', '5')
[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O true
[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O code:5
[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O Key:140285
[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O code:5
[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O Key:140285
[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O ID: 5
[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O Name: 140285
[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O
ID: 5[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O
Name: 140285[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O
ID: 5[8/4/11 11:40:13:323 CDT] 00000035 SystemOut O
Name: 140285The red color text in reality, should show different values for row2 and row3 respectively but they show the values of the first row. See below the database tables when I ran the query on the sql analyzer.
Query:
Select ccg1.caseNumber as caseNumber0_, ccg1.CaseContact_pk as CaseCont2_9_0_, ccg1.contactTypeCode as contactT3_9_0_, ccg1.folderNumber as folderNu4_9_0_, ccg1.repPayeeName as repPayee5_9_0_, ccg1.ssn as ssn9_0_ from CaseContact as ccg1 where ccg1.folderNumber=192653902 and ccg1.caseNumber=198777140 and ccg1.contactTypeCode in ('1', '2', '3', '4', '5')
Database query result:
caseNumber0_
CaseCont2_9_0_ contactT3_9_0_ folderNu4_9_0_ repPayee5_9_0_ ssn9_0_
------------ -------------- -------------- -------------- ---------------------------------
198777140 140285 5 192653902 NULL NULL
198777140 140286 5 192653902 NULL NULL
198777140 140287 1 192653902 NULL NULL