Hi,
I need to ieterate 2 lists and save to database. But I could only save the first value coming and next ones not saving into the database.
Here is my code :
Code:
List works;
WorkBasedQuote wqt = new WorkBasedQuote();
WorkBasedId workBasedId;
Work work = new Work();
Logger.getLog().debug(" getDepartments : "+getDepartments());{
//getDepartments() is the list that user selects
for (int i=0;i<getDepartments().size();i++) {
Object key = getDepartments().get(i);
Logger.getLog().debug(" deptId : "+key);
//each department may or may got more than one work.so works is the list of works that each department has got.
works = WorkFacade.getByDeptId(Integer.parseInt(key.toString()));
Logger.getLog().debug("works :"+works.size());
for (int j=0;j<works.size();j++) {
work = (Work) works.get(j);
workBasedId = new WorkBasedId(qtNo,work.getWorkId(),
Integer.parseInt(key.toString())); [b]//composite keys[/b] wqt.setWorkBasedId(workBasedId); Logger.getLog().debug(" workId : "+work.getWorkId());
WorkBasedQtFacade.saveWork(wqt);
}
}
I am saving 3 composite ids . Here, what I am trying to do is:
user can select more than one departments from a list box
Each department has got(not necessarily) more than one work
get the works of the department which user has selected
quoteNo will be returned when user saves quote details
I need to save this 3 values into another table in the database making these 3 ids as composite keys.
But here I can save only the first item, i.e., if user select a departments which has got 2 works, i could only save one work.
Could anyone help me to find out why this is happening ? Please tell if am not clear.
Thanks,
jsv.
[/list]