如何在EntityManagerFactory中使用LazyLoading

时间:2016-06-28 20:22:15

标签: java spring hibernate jpa entitymanager

我试图像这样使用EntityManagerFactory:

@Service
public class UserServiceImpl implements UserService {

@Autowired
private EntityManagerFactory entityManagerFactory;

@Override
public User getByID(long id) {
    Session session = entityManagerFactory.unwrap(Session.class);       
    return (User) session.createCriteria(User.class).add(Restrictions.idEq(id)).uniqueResult();
}

...
}

但我有错误: javax.persistence.PersistenceException:Hibernate无法将EntityManagerFactory解包为' org.hibernate.Session'

0 个答案:

没有答案