Transaction tx = null;
try {
try {
tx = session.beginTransaction();
Quote quote = new Quote();
// quote.setId(new Integer(11));
quote.setSaying("To be or not to be");
session.save(quote);
tx.commit();
// List quotes = session.find("from Quote quote where quote.id < 5"); hibernate 2
Query query = session.createQuery("from Quote quote where quote.id < 5");
List quotes = query.list();
System.out.println("HQL - List = " + quotes);
System.out.println("\nIterate over results ...");
Iterator iter = quotes.iterator();
while(iter.hasNext()) {
Quote quoteIter = (Quote) iter.next();
System.out.println(" quote id = " + quoteIter.getId());
System.out.println(" quote saying = " + quoteIter.getSaying());
}
} catch(Exception e) {
System.out.println("ERROR - Exception =" + e);
if(tx != null) {
tx.rollback();