-->
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.  [ 4 posts ] 
Author Message
 Post subject: Newbie: Wierd behavior in one-many List
PostPosted: Fri Dec 21, 2007 8:19 pm 
Newbie

Joined: Fri Dec 21, 2007 7:32 pm
Posts: 2
Iam new to hibernate and having a strange problem with bidirectional one-to-many relationship. Iam using a List and the size of the list is huge, all the elements in the list are null except for list[size-1] - this index has
the actual row that I want.

Hibernate version is 3 and Oracle 9i is the DB

Here is my mapping:

Parent - LienNoticeVO.java

Table: LienNotice - pk lien_notice_id
/**
* @hibernate.list cascade="all" lazy="true" batch-size="100"
* @hibernate.collection-one-to-many class="LienServiceDateVO"
* @hibernate.collection-index column="LIEN_SERVICE_DATE_ID"
* @hibernate.collection-key column="LIEN_NOTICE_ID"
*
*/
public List getDateOfServices() {
return dateOfServices;
}

Child - LienServiceDateVO.java

Table: Lien_service_date - pk is lien_service_date_id and it starts from 2, if that helps...
/**
* @return LienNoticeVO
* @hibernate.many-to-one class="LienNoticeVO" column="LIEN_NOTICE_ID" foreign-key="LIEN_NOTICE_ID" insert="true"
*
*/
public LienNoticeVO getLienNoticeId() {
return lienNoticeId;
}


generated sql:

select * from LIEN_SERVICE_DATE dateofserv0_ where dateofserv0_.LIEN_NOTICE_ID in (?, ?, ?, ?, ?, ?, ?)

Here is my code:

List tempList = lienNoticeVO.getDateOfServices();
if(tempList !=null){
int size=tempList.size();
for(int j=0;j<size;j++){
LienServiceDateVO tempVO = (LienServiceDateVO) tempList.get(j);
if(tempVO !=null){
//By the time code gets here loop is executed a lot many times, see my explanation below
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String date = sdf.format(tempVO.getServiceFromDate());
fromDOSList.add(date);
date = sdf.format(tempVO.getServiceToDate());
throughDOSList.add(date);
}
}
}

If lienNoticeId, which is a foreign key in child table is 8179, the size of the list is 8180. So the above 'for loop' runs for 8180 times and the single row that it has is in 8179 index in the tempList.My question is first of all why is the size of list so big and why all the columns are null? Iam expecting the
size of the list to be 1 and it should have the matching row across parent and child tables. But the actual result is very different.

Please help.

Thanks,
Radha


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 27, 2007 6:10 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

in a List every entry has a given Index within the List which is persisted to the Database by hibernate.
Because of
* @hibernate.collection-index column="LIEN_SERVICE_DATE_ID"
if there is a single entry in the List it will be located at Index LIEN_SERVICE_DATE_ID, so if this is 8179 your List will have 8180 entries.

If you don't need specific indexes within your collection use Set, SortedSet or Bag as collection-types or if you need to use List keep an appropriate Index-column in your database.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 1:49 pm 
Newbie

Joined: Fri Dec 21, 2007 7:32 pm
Posts: 2
Thanks for your reply. This is in existing code and I will have to keep using the list. However there is a DB index on the column - LIEN_SERVICE_DATE_ID. Even then, is this is the expected behavior of the List in Hibernate? Please advise.

THanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 04, 2008 4:47 pm 
Newbie

Joined: Fri Jan 04, 2008 4:46 pm
Posts: 1
I am having the same issue

Did you manage to find a solution?

I need to use List as well but want to get rid of the null elements.

Please advise.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.