zzeng

          zzeng

          為什么 XX.hbm.xml 和 XX.cfg.xml這兩個文件要放在/WEB-INF/classes/這個目錄下呢?

          為什么 XX.hbm.xml 和 XX.cfg.xml這兩個文件要放在/WEB-INF/classes/這個目錄下呢?

          因為你的所 有類放在/web-inf/classes/目錄下,所以new Configuration().configure方法是以當前目錄為根目錄(也就/web-inf/classes/目錄下)來尋找 xx.cfg.xml,否則hibernate是找不到的,除非你使用絕對路徑,或url(全球資源定位器);

          SessionFactory sf=new Configuration().configure("/hibernate/hibernate.cfg.xml").buildSessionFactory();
          hibernate會去/web-inf/classes/hibernate/目錄下去找到這個hibernate.cfg.xml

          SessionFactory sf=new Configuration().configure().buildSessionFactory();
          hibernate會去/web-inf/classes/目錄下去找到這個hibernate.cfg.xml

          當 你想用Session類的save方法把VO變成PO的時候,你就會想到Session是怎么來的,Session的對象是通過 SessionFactory類的openSession方法來實例化。有了SessionFactory你又會想到SessionFactory是怎么 來的,SessionFactory的對象是通過Configuration實例的來構建。

          Configuration類是用來管理hibernate的配置信息,如數據庫url,用戶名,密碼。。。
          Configuration 類的buildSessionFactory()用來實例化SessionFactory 。要使用buildSessionFactory方法,必須先讓Configuration.configure()方法找到 hibernate.cfg.xml文件并初始化。

          SessionFactory類是用于創建Session的實例。

          Session是Hibernate持久化操作和管理的核心。

          posted on 2005-09-28 16:22 zzeng 閱讀(1157) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 张北县| 元江| 南雄市| 深州市| 楚雄市| 临桂县| 嘉鱼县| 辽宁省| 库伦旗| 普宁市| 奇台县| 曲阜市| 拉萨市| 静宁县| 尚志市| 诸暨市| 邹平县| 新乡市| 新干县| 古交市| 枣强县| 西安市| 上蔡县| 新乡市| 吉木乃县| 多伦县| 琼中| 韶关市| 东乌| 普定县| 横峰县| 武威市| 桓台县| 景宁| 绥滨县| 六盘水市| 通化县| 普兰店市| 永福县| 汝城县| 额敏县|