欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

hibernate解决延迟加载 [main] ERROR org.hibernate.LazyInitializationException - could n

程序员文章站 2022-03-02 14:14:07
...



[main] ERROR org.hibernate.LazyInitializationException - could not initialize proxy - no Session


public Users findById(Long id){
Session session =HibernateSessionFactory.getSession();
Transaction trans = session.beginTransaction();
Users users = (Users)session.load(com.zyl.hiber.po.Users.class, id);
if(!Hibernate.isInitialized(users))Hibernate.initialize(users);
trans.commit();
session.close();
return users;


相关标签: Hibernate Java