【发布时间】:2015-08-20 08:08:52
【问题描述】:
我有两个实体:
一个 id bigint auto_inctement b_id 大整数 乙 id 大整数 日期时间戳和代码:
public void test2() {
B b = getBByA(3l);
System.out.println(b.getDate()); // <--- lazy initialization exception
}
public Revision getBByA(long a_id) {
Session session = HibernateUtil.getSessionFactory().openSession();
try {
A a = (A) session.get(A.class, a_id);
return a.getB();
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
} finally {
session.close();
}
}
如何正确接收 b.getDate()? (没有lazy="eager")
【问题讨论】:
标签: hibernate lazy-initialization