日期:2014-05-20 浏览次数:20792 次
public class HelloDaoImpl extends HibernateDaoSupport implements HelloDao { public Hello loadHelloById(Long id) { 1. Session session=getSession(); return (Hello) session.load(Hello.class,id); 2. //return (Hello) getHibernateTemplate().load(Hello.class,id); } }
Hello hello = dao.loadHelloById(new Long(1)); 3: System.out.println(hello.getId());
Exception in thread "main" org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150) at dragon.spring.hello.orm.module.Hello$$EnhancerByCGLIB$$c60e1fef.setMessage(<generated>) at dragon.spring.hello.orm.HibernateMain.main(HibernateMain.java:41) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)