I am new to hibernate. I am developing swing application using hibernate. I have created the method to fill the JTable as follows.
public static void FillTable(JTable table,String cls){
SessionFactory sf = ConnectionDao.getSessionFactory();
Session session = sf.openSession();
Query query=session.createQuery("from "+cls);//here persistent class name is cls
ClassMetadata classMetadata = sf.getClassMetadata(cls);
List l = query.list();
Object[] columnNames = classMetadata.getPropertyNames();
DefaultTableModel model = new DefaultTableModel(new Object[0][0],
columnNames);
for (int i=0; i<l.size(); i++) {
CustomerBean cb = (CustomerBean) l.get(i);
Object[] o = new Object[3];
o[0] = cb.getCustomerFName();
o[1] = cb.getCustomerCity();
o[2] = cb.getCustomerCity();
model.addRow(o);
}
table.setModel(model);
}
Above method takes the JTable and pojo class name as parameter and fill the JTable. I dont know how to make this method work for all pojo classes of any no. of properties. I am not getting any idea what to write in for loop so that it will work for all class. Because each class will have different no. of properties.
Any help will be appreciated. Thanks
new Object[0][0]as a parameter to your DefaultTableModel?