如果我们可以使用 javax.persistence.* 完成本机 Java 支持的 ORM,那么使用诸如 hibernate 之类的提供程序的真正优势是什么?
java持久化与hibernate这本书说,
Hibernate EntityManager is a wrapper around Hibernate Core that provides the
JPA programming interfaces, supports the JPA entity instance lifecycle, and allows
you to write queries with the standardized Java Persistence query language.
这里的 Hibernate EntityManager 这个名字让我很困惑。EntityManager 是否属于休眠?
以下是如何通过 java 持久化来持久化域对象,
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("helloworld");
// First unit of work
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
下面是使用的persistence.xml文件,
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="helloworld">
<properties>
<property name="hibernate.ejb.cfgfile"
value="/hibernate.cfg.xml"/>
</properties>
</persistence-unit>
</persistence>
所以这里再次持久化单元声明休眠配置文件。那么对象 Persistence.createEntityManagerFactory("helloworld"); 居然是在这里重播?
EntityManager em = emf.createEntityManager();
createEntityManager() 方法持有哪个对象?