2

我试图使用 JPA 使用 JDBC:ODBC 连接连接到 MS 访问数据库。这是我的 Persistance.xml 代码:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
    <persistence-unit name="DSRJPA">
    <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
    <class>com.entity.AccessEntity</class>
    <properties>
    <property name="toplink.jdbc.url" value="jdbc:odbc:MSAccessDB"/>
    <property name="toplink.jdbc.user" value="admin"/>
    <property name="toplink.jdbc.driver" value="sun.jdbc.odbc.JdbcOdbcDriver"/>
    <property name="toplink.jdbc.password" value="admin"/>
    <property name="toplink.jdbc.read-connections.min" value="1"/>   
    <property name="toplink.jdbc.write-connections.min" value="1"/> 
    </properties>
    </persistence-unit>
</persistence>

但是当我运行代码时,我得到了这个错误:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named DSRJPA:  The following providers:
oracle.toplink.essentials.PersistenceProvider
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
Returned null to createEntityManagerFactory.

    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at com.test.Access.main(Access.java:19)

请告诉我这个错误。提前致谢。

4

1 回答 1

0

你在课堂上引用过你的持久化单元吗?

IE

EntityManagerFactory emf = Persistence.createEntityManagerFactory("DSRJPA");
于 2013-01-18T10:29:19.747 回答