到目前为止,我仍然在没有 DAO 的情况下使用 JSF 和 JPA。现在我想使用 DAO。但是如何在 DAO 类中初始化 EntityManager?
public class AdresseHome {
@PersistenceContext
private EntityManager entityManager;
public void persist(Adresse transientInstance) {
log.debug("persisting Adresse instance");
try {
entityManager.persist(transientInstance);
log.debug("persist successful");
} catch (RuntimeException re) {
log.error("persist failed", re);
throw re;
}
}
}
我是否要使用 Spring 或者是否有没有 Spring 的解决方案?
谢谢。