I am creating a java bean from a master detail table. Lets call the master table A and Detail table B. When I make this in to a java bean I have BeanA and BeanB. BeanA will have all the relavant rows in the A table and will also have a list collection of BeanB (detail table B) based on the primarykey. So BeanA will look like
class BeanA {
String property1;
String Property2;
List<BeanB> lstpropery; //This is the data of detail table based on the primary key
}
In this scenerio I am using Spring JDBC to query the table. So when I query the table A and loop through the resultset and set the BeanA properties, I will also set the lstproperty by doing the query to B table.
so the code will be
String qry = "select * from A';
result = this.queryTemplate.query(qry, obj, new RowMapper(){
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
BeanA bean1= new BeanA();
bean1.setProperty1(rs.getString(1));
bean1.setProperty2(rs.getString(2));
bean1.setLstpropery(callTableB(String primaryKey)); // I see a performance issue here
return bean1;
}
});
Is there a better way to do this?
If you have a chance to use Hibernate, then lazy-fetching concept might be useful here.