3

I'm using DBUtils in my simple project. I have Item and Person entity class (persons and items as tables in database). This simplified the class to better show what I mean. Now i need to get list of items with login names using BeanListHandler. To do this i added login property to Item, but this is ugly solution. Is something better to do that and use advantages of BeanListHandler?

public class Person {
   private Long id;
   private String login;
}

public class Item {
   private Long id;
   private String name;
   // ... a lot more properties of item

   private Long personId;  // this is real column in "items" table
   private String login;   // UGLY (login is not in "items" table, only for BeanListHandler)
}

QueryRunner q = new QueryRunner(getDataSource());
String sql = "select i.*, p.login from items i, persons p where p.id = i.personId";
List<Item> l = (List<Item>) q.query(sql, new BeanListHandler<Item>(Item.class));
marioosh
  • 27,328
  • 49
  • 143
  • 192

0 Answers0