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
|