You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by xianwinwin <xi...@gmail.com> on 2008/07/13 19:22:22 UTC

how to return a LIST and populate it in an object

I have a query that returns from the db an arrayList of class CarBean:

carID, model, color, rentUserID, fname, lname, dateRentStart, dateRentEnd


The query is with reference to a particular car that N people (rentUserID)
rented and the user (the system user) wish to know how many rentals were
made for this carID.

I wish to populate the result into ONE class name CarRental which looks like
this:

private Car; //model
private List<RentUser> rentals; //all info relating to rentUser

so, my question is this, using iBatis is there a way to have a LIST of
RentUser and a Car object so the CarRental object will have the Car object
and a LIST of rentUser. 


right now, I'm doing this

Iterator<CarBean> itr = list.iterator();
CarRental carRental = new CarRental();
List rentals = new ArrayList();
while (itr.hasNext())
{
    CarBean cb = itr.next();
    carRental.setCarID(cb.getCarID);
    .
    .
    .
    //for the list of users:
   User u = new User();  
   u.setUserID(cb.getUserID());  
   .
   . 
   .
   rentals.add(u);
}
 
 
carRental.setRentals(rentals);


* please consider a more complicated query that the end result of ONE object
should have X arrayList and other M objects in it

thank you!
-- 
View this message in context: http://www.nabble.com/how-to-return-a-LIST-and-populate-it-in-an-object-tp18431512p18431512.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.