-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: HSQL returning the only the first row
PostPosted: Thu Aug 04, 2011 1:02 pm 
Newbie

Joined: Wed Aug 17, 2005 10:50 am
Posts: 11
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: 140285


The 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


Top
 Profile  
 
 Post subject: Re: HSQL returning the only the first row
PostPosted: Tue Aug 09, 2011 10:19 am 
Newbie

Joined: Wed Aug 17, 2005 10:50 am
Posts: 11
Found the answer to the problem. After attempts of debugging I found that the caseCon.hbm.xml had the mistake.

I was identifying caseNum to be primary key instead of caseContKey. Usually the correct field should be identified as the pk and not any field. It is fixed now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.