我有一本普通的Java类书,标注为jpa的Entity。 我配置了持久性xml,但是我有很大的堆栈跟踪,但有我不理解的异常。另外,我在javax.persistence中找不到jdbc包。我怎么办?
这是我的实体
package Java.JPA;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Book
{
@Id @GeneratedValue
private long id;
private String title;
public Book()
{
}
public Book(String title) {
this.title = title;
}
public String getTitle()
{
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
这是我的主要课程
package Java;
import Java.JPA.Book;
import java.sql.SQLException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
public class main
{
public static void main(String[] args) throws SQLException, ClassNotFoundException {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("example");
EntityManager em = emf.createEntityManager();
Book book = new Book("TestJPA");
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(book);
tx.commit();
em.close();
emf.close();
}
}
这是我的persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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_1.xsd"
version="2.1">
<persistence-unit name="example">
<!--<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>-->
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>Java.JPA.Book</class>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/studyJPA"/>
<property name="javax.persistence." value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
</properties>
</persistence-unit>
</persistence>
堆栈跟踪:
"C:\Program Files\Java\jdk1.8.0_92\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.2\lib\idea_rt.jar=55859:C:\Program Files\JetBrains\IntelliJ IDEA 2017.3.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_92\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_92\jre\lib\rt.jar;C:\Tomcat\apache-tomcat-9.0.7\lib\servlet-api.jar;C:\Users\Anton\Desktop\study\target\classes;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\javaee-api-7.0-1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jsp-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\servlet-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\el-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jasper.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\ecj-4.6.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jasper-el.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jaspic-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-jni.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina-ha.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\serp-1.15.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-dbcp.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-jdbc.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-util.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xalan-2.7.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina-ant.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\hawtbuf-1.11.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\howl-1.0.1-1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\hsqldb-2.3.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jasypt-1.9.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\mimepull-1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\neethi-3.0.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wsdl4j-1.6.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xmlsec-2.0.6.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\joda-time-2.7.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openjpa-2.4.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\stax-ex-1.7.4.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-coyote.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\websocket-api.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activation-1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\bval-jsr-1.1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jaxb-api-2.3.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\stax-api-1.0-2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-i18n-es.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-i18n-fr.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-i18n-ja.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\bval-core-1.1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina-tribes.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-cli-1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cryptacular-1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-core-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jaxb-core-2.3.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\jaxb-impl-2.3.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\stax2-api-3.1.4.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\sxc-runtime-0.8.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-lang-2.6.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\saaj-impl-1.3.23.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\serializer-2.7.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\slf4j-api-1.7.21.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-util-scan.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomcat-websocket.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-jdbc-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-naming-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xml-resolver-1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-dbcp2-2.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-lang3-3.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-pool2-2.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-api-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-cxf-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-javaagent.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-jee-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\sxc-jaxb-core-0.8.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-jaxrs-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-reflect-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-ra-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-codec-1.10.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-wsdl-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\java-support-7.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\johnzon-core-1.0.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\myfaces-api-2.2.12.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-core-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-ejbd-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-hsql-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-http-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-rest-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\slf4j-jdk14-1.7.21.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-common-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-loader-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-webapp-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-policy-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\bcprov-jdk15on-1.60.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-logging-1.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\johnzon-jaxrs-1.0.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\johnzon-jsonb-1.0.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\myfaces-impl-2.2.12.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-core-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-mojarra-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-myfaces-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\catalina-storeconfig.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-digester-1.8.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-jcs-core-2.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\johnzon-mapper-1.0.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-client-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-cxf-rs-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-loader-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-server-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\swizzle-stream-1.6.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-catalina-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-bindings-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xmlschema-core-2.2.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-protobuf-1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-ws-addr-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-ee-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-asm6-shaded-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-bundleutils-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-broker-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-client-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-jcs-jcache-2.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-security-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-ejb-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-jsf-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-spi-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-web-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-beanutils-1.9.3.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-client-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-ws-policy-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-saml-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-soap-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-el22-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-impl-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\tomee-webservices-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\woodstox-core-asl-4.4.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\xbean-finder-shaded-4.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-management-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\geronimo-connector-3.1.4.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-saml-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xacml-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\commons-collections-3.2.2.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-ws-security-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-webservices-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xacml-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xmlsec-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-jdbc-store-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-bindings-xml-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\geronimo-transaction-3.1.4.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\mbean-annotation-api-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-profile-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xmlsec-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\quartz-openejb-shade-2.2.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-bindings-soap-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-json-basic-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-security-saml-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\geronimo-jsonb_1.0_spec-1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-cxf-transport-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-jee-accessors-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-security-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\taglibs-standard-impl-1.2.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\taglibs-standard-spec-1.2.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-ws-security-dom-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-kahadb-store-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-frontend-jaxrs-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-frontend-jaxws-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-security-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openwebbeans-ee-common-1.7.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-ws-security-stax-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\batchee-jbatch-0.4-incubating.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-frontend-simple-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-transports-http-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\openejb-jpa-integration-7.1.0.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xacml-saml-api-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\taglibs-standard-jstlel-1.2.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-databinding-jaxb-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-security-cors-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-security-jose-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\opensaml-xacml-saml-impl-3.1.1.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-ws-security-common-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\activemq-openwire-legacy-5.14.5.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-security-oauth2-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-extension-search-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\wss4j-ws-security-policy-stax-2.1.9.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-extension-providers-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-security-jose-jaxrs-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\cxf-rt-rs-service-description-3.1.15.jar;D:\Program\TomEE+\apache-tomee-plus-7.1.0\lib\geronimo-javamail_1.4_mail-1.9.0-alpha-2.jar;C:\Users\Anton\.m2\repository\mysql\mysql-connector-java\8.0.12\mysql-connector-java-8.0.12.jar;C:\Users\Anton\.m2\repository\com\google\protobuf\protobuf-java\2.6.0\protobuf-java-2.6.0.jar;C:\Users\Anton\.m2\repository\org\hibernate\hibernate-core\5.3.6.Final\hibernate-core-5.3.6.Final.jar;C:\Users\Anton\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\Anton\.m2\repository\javax\persistence\javax.persistence-api\2.2\javax.persistence-api-2.2.jar;C:\Users\Anton\.m2\repository\org\javassist\javassist\3.23.1-GA\javassist-3.23.1-GA.jar;C:\Users\Anton\.m2\repository\net\bytebuddy\byte-buddy\1.8.17\byte-buddy-1.8.17.jar;C:\Users\Anton\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\Anton\.m2\repository\org\jboss\spec\javax\transaction\jboss-transaction-api_1.2_spec\1.1.1.Final\jboss-transaction-api_1.2_spec-1.1.1.Final.jar;C:\Users\Anton\.m2\repository\org\jboss\jandex\2.0.5.Final\jandex-2.0.5.Final.jar;C:\Users\Anton\.m2\repository\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;C:\Users\Anton\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;C:\Users\Anton\.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;C:\Users\Anton\.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.0.4.Final\hibernate-commons-annotations-5.0.4.Final.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\javax.persistence\2.2.1\javax.persistence-2.2.1.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.jpa\2.7.3\org.eclipse.persistence.jpa-2.7.3.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.asm\2.7.3\org.eclipse.persistence.asm-2.7.3.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.antlr\2.7.3\org.eclipse.persistence.antlr-2.7.3.jar;C:\Users\Anton\.m2\repository\javax\json\javax.json-api\1.1.2\javax.json-api-1.1.2.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.jpa.jpql\2.7.3\org.eclipse.persistence.jpa.jpql-2.7.3.jar;C:\Users\Anton\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.core\2.7.3\org.eclipse.persistence.core-2.7.3.jar" Java.main
91 INFO [main] openjpa.Runtime - OpenJPA dynamically loaded the class enhancer. Any classes that were not enhanced at build time will be enhanced when they are loaded by the JVM.
121 INFO [main] openjpa.Runtime - Starting OpenJPA 2.4.3
Exception in thread "main" <openjpa-2.4.3-r422266:1833086 fatal user error> org.apache.openjpa.persistence.ArgumentException: The persistence provider is attempting to use properties in the persistence.xml file to resolve the data source. A Java Database Connectivity (JDBC) driver or data source class name must be specified in the openjpa.ConnectionDriverName or javax.persistence.jdbc.driver property. The following properties are available in the configuration: "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@2655aabb".
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:71)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:850)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:603)
at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1520)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:535)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:460)
at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:121)
at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:973)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:964)
at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:642)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:202)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:154)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
at Java.main.main(main.java:15)
Process finished with exit code 1
在依赖项pom.xml中有休眠和mysql驱动程序。另外,我从tomcat的目录中导入javaee-api-7.0-1.jar,servlet-api.jar和jsp-api.jar。请帮忙。我尝试解决了几个多小时。我将不胜感激!
这是我的java ee jar文件。没有jdbc软件包或其他名称为“ jdbc”的文件
也许,我下载了错误的tomcat ee。如果是这样,请给我一个下载正确版本的链接。
我不知道发生了什么,但是我有新的例外情况
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/geronimo/osgi/locator/ProviderLocator
at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:108)
at javax.persistence.Persistence.getProviders(Persistence.java:275)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:88)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
at Java.main.main(main.java:14)
Caused by: java.lang.ClassNotFoundException: org.apache.geronimo.osgi.locator.ProviderLocator
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
这很神奇:)现在我有一个问题。该如何解决?
答案 0 :(得分:0)
<persistence>
<persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
<class>org.hibernate.ejb.test.Apple</class>
<class>org.hibernate.ejb.test.Distributor</class>
<class>org.hibernate.ejb.test.Fruit</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:."/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item"
value="read-write"/>
<property name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors"
value="read-write, RegionName"/>
</properties>
</persistence-unit>
</persistence>