天空是藍色的

          做好軟件為中國 #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 閱讀(534) 評論(0)  編輯  收藏 所屬分類: 工作總結

          主站蜘蛛池模板: 台州市| 锡林浩特市| 无棣县| 老河口市| 邮箱| 安多县| 宜黄县| 昌黎县| 昭觉县| 尉犁县| 鱼台县| 靖远县| 济阳县| 鹰潭市| 新郑市| 上栗县| 屏南县| 光山县| 宜黄县| 多伦县| 莆田市| 大洼县| 阿坝| 靖远县| 鹤壁市| 桂平市| 连城县| 涡阳县| 弥渡县| 如东县| 临漳县| 临朐县| 云林县| 丰城市| 葵青区| 洮南市| 弋阳县| 雷山县| 三河市| 鞍山市| 博兴县|