我刚接触javaee、jdbc和jpa。实际上,我已经通过jpa tools->generate entities from tables导入实体类,自动生成了实体类。
当我尝试运行此测试时:
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import model.User;
public class TestConnection {
@PersistenceContext(unitName = "QuestionnaireEJB")
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("QuestionnaireEJB");
EntityManager em = emf.createEntityManager();
TestService testService = new TestService(em);
//find an User by is id
em.getTransaction().begin();
User user = testService.findUser(1);
System.out.println("found User:" + user);
}
}
对于我的应用程序,我收到以下错误消息:
持久性提供程序正在尝试使用persistence.xml文件中的属性来解析数据源。必须在中指定java数据库连接(jdbc)驱动程序或数据源类名 openjpa.ConnectionDriverName
或者 javax.persistence.jdbc.driver
财产。
配置中提供了以下属性:“org.apache.openjpa.jdbc.conf。jdbcconfigurationimpl@a3ffd38e"
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="QuestionnaireEJB">
<jta-data-source>QuestionnaireEJB</jta-data-source>
<class>model.Accesstime</class>
<class>model.Contain</class>
<class>model.ContainPK</class>
<class>model.Marketingquestion</class>
<class>model.Offensiveword</class>
<class>model.Product</class>
<class>model.Questionnaire</class>
<class>model.QuestionnairePK</class>
<class>model.Review</class>
<class>model.ReviewPK</class>
<class>model.User</class>
</persistence-unit>
</persistence>
这是我的 persistence.xml
文件位于 ejbModule/META-INF/persistence
.
暂无答案!
目前还没有任何答案,快来回答吧!