2017-01-23 78 views
0

我試圖用JPA 2.1,Hibernate和MariaDB創建基本的CRUD。無法建立實體管理器工廠,無法加載驅動程序

當我嘗試運行我的Tomcat項目,我得到這個錯誤:

​​

我的數據庫是啓動和運行。我通過maven獲取JDBC驅動程序,JAR存在於Maven Dependencies文件夾中。下面是persistence.xml中(我也跟着在Pro JPA 2.1教科書爲例):

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.1" 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"> 
<persistence-unit name="CRUD"> 

    <properties> 
     <property name="javax.persistence.jdbc.driver" 
        value="mariadb-java-client-1.1.7"/> 
     <property name="javax.persistence.jdbc.url" 
        value="jdbc:derby://localhost:3306/Practice;create=true"/> 
     <property name="javax.persistence.jdbc.user" value="root"/> 
     <property name="javax.persistence.jdbc.password" value="password"/> 
    </properties> 

</persistence-unit> 

POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>CRUD</groupId> 
<artifactId>CRUD</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 
<build> 
    <sourceDirectory>src</sourceDirectory> 
    <resources> 
     <resource> 
      <directory>src</directory> 
      <excludes> 
       <exclude>**/*.java</exclude> 
      </excludes> 
     </resource> 
    </resources> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.5.1</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>3.0.0</version> 
      <configuration> 
       <warSourceDirectory>WebContent</warSourceDirectory> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<dependencies> 
    <!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client --> 
    <dependency> 
     <groupId>org.mariadb.jdbc</groupId> 
     <artifactId>mariadb-java-client</artifactId> 
     <version>1.1.7</version> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>5.1.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-entitymanager</artifactId> 
     <version>5.1.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-c3p0</artifactId> 
     <version>5.1.0.Final</version> 
    </dependency> 
</dependencies> 

回答

2

您的意見是錯誤的。 javax.persistence.jdbc.driver應該設置爲JDBC驅動程序的CLASS NAME,而不是一些jar名稱!

<property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver"/> 
相關問題