天空是藍色的

          做好軟件為中國 #gcc -c helloworld.c -o helloworld.o //編譯目標文件 #gcc helloworld.o -o helloworld //編譯成可執行exe #helloworld //運行exe
          數據加載中……
          Hibernate的分頁
           Session session = HibernateUtil.currentSession();

          Transaction tx 
          = session.beginTransaction();
          Query query 
          = session.createQuery("from Cat");

          query.setFirstResult(
          0);//開始
          query.setMaxResult(10);//最大
          for (Iterator it = query.iterate(); it.hasNext();) {
                
          //Object obj = it.next();
          }

          tx.commit();
          HibernateUtil.closeSession();

          HibernateUtil.java

          public class HibernateUtil {
              
          private static final SessionFactory sessionFactory;

              
          static {
                  
          try {
                      
          // Create the SessionFactory
                      Configuration cfg = new Configuration().configure();
                      sessionFactory 
          = cfg.buildSessionFactory();
                  }
           catch (Throwable ex) {
                      
          throw new ExceptionInInitializerError(ex);
                  }

              }


              
          public static final ThreadLocal session = new ThreadLocal();

              
          public static Session currentSession() {
                  Session s 
          = (Session) session.get();
                  
          if (s == null{
                      
          try {
                          s 
          = sessionFactory.openSession();
                      }
           catch (HibernateException e) {
                          
          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }

                      session.set(s);
                  }

                  
          return s;
              }


              
          public static void closeSession() {
                  Session s 
          = (Session) session.get();
                  
          if (s != null)
                      
          try {
                          s.close();
                      }
           catch (HibernateException e) {
                          
          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }

                  session.set(
          null);
              }


          }

          posted on 2005-12-21 14:16 bluesky 閱讀(533) 評論(0)  編輯  收藏 所屬分類: 工作總結

          主站蜘蛛池模板: 大丰市| 定边县| 凤冈县| 长海县| 高碑店市| 米泉市| 彰武县| 连平县| 兴海县| 文登市| 辉县市| 沙坪坝区| 夏河县| 乡城县| 蒲江县| 双流县| 津市市| 高州市| 鸡东县| 金昌市| 铜川市| 平舆县| 开鲁县| 塔城市| 乐至县| 虎林市| 青河县| 桦南县| 兴文县| 塔河县| 会同县| 印江| 闸北区| 樟树市| 隆回县| 石城县| 邹平县| 铜梁县| 鲁甸县| 县级市| 庆阳市|