【发布时间】:2012-12-27 15:22:24
【问题描述】:
在我加入的新项目中,他们一直交替使用术语 Hibernate 和 JPA。因此,我尝试深入研究代码并尝试了解整个事情是如何工作的(我是 Spring、JPA 和 Hibernate 世界的新手)。我将尝试将代码放在这里以便更好地理解: 1) 有一个@Configuration 类,它们具有以下内容:
@Resource
private HibernateJpaVendorAdapter hibernateOracleJpaVendorAdapter;
LocalContainerEntityManagerFactoryBean entityManager =
new LocalContainerEntityManagerFactoryBean();
entityManager.setJpaVendorAdapter(hibernateOracleJpaVendorAdapter);
entityManager.setPersistenceUnitName("abc");
.
.
所以,在这个配置类中,我们返回一个 EntityManagerFactory。
2)然后有一个标记为@Persistor的持久化类,其中调用了repository的方法(例如,用于保存操作):
blahblahRepository.save(blahblahEntity, abcdef);
3) 最后有一个被注释为@Repository 的存储库类。再说一遍,他们有这段代码:
@PersistenceContext(unitName = "same as the name in persistence.xml")
protected EntityManager entityManager;
“save”方法包裹了JPA的persist方法:
getEntityManager().persist(entityObject);
我的问题如下: 1) 除了 hibernateJpaVendorAdapter 之外,没有关于 Hibernate 的任何消息。我搜索了整个工作区,它只显示了 3 次出现 hibernate 一词,都在配置文件中。 2)从我所拥有的任何知识来看,应该使用 EntityManagerFactory 或 EntityManager 但我们两者都做?
【问题讨论】: