我在目录下persistence.xml使用相同的名字。然后,我用以下代码调用它:TopLinkMETA-INF
persistence.xml
TopLinkMETA-INF
EntityManagerFactory emfdb = Persistence.createEntityManagerFactory("agisdb");
但是,我收到以下错误消息:
2009-07-21 09:22:41,018 [main]错误-名为agisdb的EntityManager的持久性提供程序没有 javax.persistence.PersistenceException:名为agisdb的EntityManager的持久性提供程序 在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89) 在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
这是persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> <persistence-unit name="agisdb"> <class>com.agis.livedb.domain.AddressEntity</class> <class>com.agis.livedb.domain.TrafficCameraEntity</class> <class>com.agis.livedb.domain.TrafficPhotoEntity</class> <class>com.agis.livedb.domain.TrafficReportEntity</class> <properties> <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/agisdb"/> <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="toplink.jdbc.user" value="root"/> <property name="toplink.jdbc.password" value="password"/> </properties> </persistence-unit> </persistence>
它应该在类路径中。但是,我得到了上面的错误。
在之后<persistence-unit name="agisdb">,定义持久性提供程序名称:
<persistence-unit name="agisdb">
<provider>org.hibernate.ejb.HibernatePersistence</provider>