1 26 27 29 package de.nava.informa.impl.hibernate; 30 31 import java.util.Iterator ; 32 import java.util.List ; 33 34 import net.sf.hibernate.HibernateException; 35 import net.sf.hibernate.Session; 36 import net.sf.hibernate.Transaction; 37 38 44 public class DemoChannelHibernate { 45 46 public static void main(String [] args) throws Exception { 47 SessionHandler handler = SessionHandler.getInstance(); 48 Session session = handler.getSession(); 49 ChannelBuilder builder = new ChannelBuilder(session); 50 Transaction tx = null; 51 52 try { 54 tx = session.beginTransaction(); 55 List result = session.find("from Channel"); 58 tx.commit(); 61 Iterator it = result.iterator(); 62 while (it.hasNext()) { 63 Channel c = (Channel) it.next(); 64 System.out.println("retrieved channel --> " + c.getId()); 65 System.out.println(" c: " + c); 66 Iterator it_items = c.getItems().iterator(); 67 while (it_items.hasNext()) { 68 Item item = (Item) it_items.next(); 69 System.out.println(" * " + item); 70 } 71 } 72 } catch (HibernateException he2) { 73 if (tx != null) tx.rollback(); 74 throw he2; 75 } 76 finally { 77 session.close(); 78 } 79 80 109 110 114 } 115 116 } 117 | Popular Tags |