我正在尝试连接到两个不同的数据库,我能够连接到一个,但另一个是抛出错误,说“没有持久性提供程序..不确定我在这里做了什么错,但下面是我的persistence.xml,这是放在src / Meta-Inf文件夹下。
<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_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="test1"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.jpa.hibernate.test.entity.Agency</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.ibm.as400.access.AS400JDBCDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:as400://host/" />
<property name="javax.persistence.jdbc.user" value="***" />
<property name="javax.persistence.jdbc.password" value="***" />
<property name="hibernate.connection.pool_size" value="1" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />
<property name="show_sql" value="true" />
<property name="hibernate.temp.use_jdbc_metadata_defaults"
value="false" />
</properties>
</persistence-unit>
<persistence-unit name="test2" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- <jta-data-source>jdbc/MyDatasource</jta-data-source> -->
<class>org.jpa.hibernate.test.entity.Student</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/***" />
<property name="javax.persistence.jdbc.user" value="***" />
<property name="javax.persistence.jdbc.password" value="***" />
<property name="hibernate.connection.pool_size" value="1" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="show_sql" value="true" />
<property name="hibernate.temp.use_jdbc_metadata_defaults"
value="false" />
</properties>
</persistence-unit>
</persistence>
以下是我的整个堆栈跟踪:
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.javax.persistence.PersistenceException: No Persistence provider for EntityManager named test1
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.jpa.hibernate.test.entity.EntityManagerUtil.<clinit>(EntityManagerUtil.java:30)
at org.jpa.hibernate.test.entity.JPAExample.<init>(JPAExample.java:10)
at org.jpa.hibernate.test.entity.JPAExample.main(JPAExample.java:14)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named test1
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at org.jpa.hibernate.test.entity.EntityManagerUtil.<clinit>(EntityManagerUtil.java:15)
... 2 more
请帮帮我。
谢谢,