天空是藍(lán)色的

          做好軟件為中國(guó) #gcc -c helloworld.c -o helloworld.o //編譯目標(biāo)文件 #gcc helloworld.o -o helloworld //編譯成可執(zhí)行exe #helloworld //運(yùn)行exe
          數(shù)據(jù)加載中……
          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 閱讀(538) 評(píng)論(0)  編輯  收藏 所屬分類: 工作總結(jié)

          主站蜘蛛池模板: 布拖县| 唐河县| 乌拉特中旗| 堆龙德庆县| 泰安市| 东至县| 高雄市| 阿拉善盟| 陕西省| 哈密市| 霍州市| 肥东县| 嵊州市| 博兴县| 江口县| 深圳市| 兰溪市| 九江县| 高密市| 乌兰浩特市| 三台县| 桐柏县| 虎林市| 玛沁县| 榕江县| 磐安县| 阿克陶县| 德令哈市| 赣州市| 金昌市| 南通市| 申扎县| 高阳县| 庆云县| 康乐县| 闻喜县| 宁安市| 静安区| 灵璧县| 鱼台县| 红原县|