aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernalte HSQL returning the only the first row Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernalte HSQL returning the only the first row" Watch "Hibernalte HSQL returning the only the first row" New topic
Author

Hibernalte HSQL returning the only the first row

Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 117
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.




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')




Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 117
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.
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 145
I would like to know experts' opinion on this behaviour. Query in question should always return 3 rows irrespective of what the primary key is .
Hemant Thard
Ranch Hand

Joined: Dec 23, 2008
Posts: 122
Hi Jitesh,

Here's what i think is happening
3 rows are returned by prepared statement to hibernate(at very low level).

hibernate iterates through this rows. for the first row, hibernate gets the primary key, checks the cache for the presence of this key, if not found create a new persistence object.
for second row, it again gets primary key, check the cache. This time object exists in cache, so returns cache object .
same for the third row.

That is why
I am able to see only the first row value when I iterate the result1 list.



Hope this is clear.
Hemant
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernalte HSQL returning the only the first row