當試圖從數據庫項目,我得到這個錯誤:Hibernate的JPA,Spring MVC和LazyInitializationException中
13:00:13.876 [[email protected]] ERROR o.h.LazyInitializationException - failed to lazily initialize a collection of role: bo.myobj, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: de.myob.linkedstuff, no session or session was closed
我瞭解,切換到渴望,而不是延遲加載解決了這個問題,例如
@OneToMany(mappedBy = "myobj", cascade = CascadeType.ALL, fetch=FetchType.EAGER)
我也明白,急切的加載是不鼓勵的。爲了解決這個問題,最好的做法是什麼?
感謝提示,我想這是正確的策略。但是,自從我開始使用ORM後,我遇到了很多問題,我想知道是否有是任何使用* any * ORM的好處...對不起,只是*有*提到:-( – 2010-07-24 16:26:33
@erlord:隨意不使用ORM(至少沒有定義的持久化上下文)然後:)運氣! – 2010-07-24 17:31:17