我试图像这样使用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'