Posted Sunday, June 13, 2004 @ 20:55:40
You can easily integrate quicktable with hibernate
To show a list of objects which are retreived using Hibernate
Session session =sessionFactory.openSession();
List allAuctions = session.createQuery("from AuctionItem").list();
dbTable.refreshDataObject(allAuctions,null);
When user modifies data in QuickTable, if you have to update the data using Hibernate, then you have to attach a DatabaseChangeListener to QuickTable and implement the DatabaseChangeListener as below
class HibernateListener extends DatabaseChangeListener
{
public boolean beforeUpdate(int row)
{
Session session =sessionFactory.openSession();
Transaction tx =session.beginTransaction();
AuctionItem item = (AuctionItem)session.get(ActionItem.class, itemId);
tx.commit();
session.close();
//get value from each cell in this row and set the value into AuctionItem
//e.g
item.setXXX(dbTable.getValueAt(row,1);
Session session2 =sessionFactory.openSession();
Transaction tx =session2.beginTransaction();
session2.update(item);
tx.commit();
session2.close();
return true;
}
public boolean beforeInsert(int row)
{
//get the objects in this row & insert using hibernate
return true;
}
public boolean beforeDelete(int row)
{
//delete this Object using hibernate
return true;
}
}