ITeye博客

[Hibernate] one cause of LazyInitializationException

SilverRing · 2010-10-19 16:08 · Hibernate · 企业架构 · Markdown

Sometimes a LazyInitializationException will be thrown on getHibernateTemplate().load().

Reason being when using load(), Hibernate simply retrieves you a Proxy, which has only the id set, rest of the fields being queried from database when needed. At that time, the hibernate session might have been closed.

A quick fix: replace .load() with .get(). It'll fetch the result immediately.

评论(1)

  1. #1 楼 · DavyLee · 2011-01-28 23:25

    简直扯淡,get和load都报同样的错!

评论功能维护中,当前仅展示历史评论。