-->
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: iterate and saveorUpdate
PostPosted: Mon Nov 13, 2006 7:44 am 
Beginner
Beginner

Joined: Fri Jan 13, 2006 8:07 am
Posts: 29
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]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 9:15 am 
Beginner
Beginner

Joined: Fri Jan 13, 2006 8:07 am
Posts: 29
I sorted the problem. It was a silly mistake in my code.

Thanks.


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.