Junky's IT Notebook

          統計

          留言簿(8)

          積分與排名

          WebSphere Studio

          閱讀排行榜

          評論排行榜

          使用hibernate經常碰到的一些異常介紹

          在使用hibernate過程中經常碰到一些異常,有些很常見,經過個人經驗和網上的搜集,也總結一下:

          一.CGLIB異常

          org.springframework.orm.hibernate.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.anyi.fa.model.FaCard.setCardND; nested exception is net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.anyi.fa.model.FaCard.setCardND
          net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.anyi.fa.model.FaCard.setCardND
          ?at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:220)
          ?at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2224)
          ?at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:319)
          ?at net.sf.hibernate.loader.Loader.doQuery(Loader.java:309)
          ?at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
          ?at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:941)
          ?at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:961)
          ?at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
          ?at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
          ?at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:413)
          ?at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2131)

          ?此中異常比較常見,一般是因為null造成的。例如:一個int映射到數據庫中,但從數據庫讀取時是null值這樣就會出現此中異常。

          解決方式:如果允許為空的字段做一包裝(int-->Integer,long-->Long,double--->Double等),其實這在系統設計時就應該根據實際情況考慮到的。

          二 。延遲加載問題

          net.sf.hibernate.LazyInitializationException:

          ?Failed to lazily initialize a collection - no session or session was closed

          此類問題也是比較常見的,一般是由于采用了延遲加載機制(lazy=true),在session關閉之后又調用延遲加載的數據或方法造成的。

          解決方式:

          ?? 在session關閉之前讀取,或調用HIbernate.initalize()方法。

          三.BigDecimal屬性映射時要指定小數位數。

          四.其他就是一些級聯更新刪除,主外建約束錯誤,操作主,子表順序的問題了,一般比較容易解決. ?



          Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1108781

          posted on 2006-08-25 10:19 junky 閱讀(624) 評論(0)  編輯  收藏 所屬分類: hibernate

          主站蜘蛛池模板: 友谊县| 方城县| 益阳市| 乐业县| 团风县| 马山县| 永川市| 盐边县| 扶绥县| 菏泽市| 北宁市| 庆元县| 静乐县| 成都市| 贵溪市| 图木舒克市| 平谷区| 西平县| 板桥市| 新巴尔虎左旗| 额尔古纳市| 临汾市| 巩义市| 新龙县| 拜城县| 文化| 洪泽县| 封丘县| 饶阳县| 河曲县| 南宫市| 望奎县| 方正县| 绥芬河市| 永定县| 常熟市| 天镇县| 嘉义市| 比如县| 封丘县| 灵寿县|