2017-06-07 424 views
0

我正在將一箇舊的eclipse IVY項目轉換爲maven。在舊項目中使用eclipselink,我希望它使用休眠。另一個「沒有持久性提供者的EntityManager名爲X」

我已經創建了幾個使用Hibernate的項目,所以我使用了我的persistence.XML,並更改了需要更改的部分。

雖然我遇到問題;它找不到我的持久性提供者。 在我的POM中,我嘗試過使用hibernate-core依賴項,而hibernate-persistence-provider-none都沒有工作。

至於現在,我的POM如下:

<?xml version="1.0" encoding="UTF-8"?> 
<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>test.dk</groupId> 
<artifactId>test-test</artifactId> 
<packaging>war</packaging> 
<version>4.1</version> 
<name>test</name> 

<prerequisites> 
    <maven>3</maven> 
</prerequisites> 

<properties> 
    <vaadin.version>7.7.8</vaadin.version> 
    <vaadin.plugin.version>7.7.8</vaadin.plugin.version> 
    <jetty.plugin.version>9.3.9.v20160517</jetty.plugin.version> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <maven.compiler.source>1.8</maven.compiler.source> 
    <maven.compiler.target>1.8</maven.compiler.target> 
    <!-- If there are no local customisations, this can also be "fetch" or "cdn" --> 
    <vaadin.widgetset.mode>local</vaadin.widgetset.mode> 
</properties> 

<repositories> 
    <repository> 
     <id>vaadin-addons</id> 
     <url>http://maven.vaadin.com/vaadin-addons</url> 
    </repository> 
</repositories> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>com.vaadin</groupId> 
      <artifactId>vaadin-bom</artifactId> 
      <version>${vaadin.version}</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<dependencies> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.0.1</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>com.vaadin</groupId> 
     <artifactId>vaadin-server</artifactId> 
    </dependency> 


    <dependency> 
     <groupId>com.vaadin</groupId> 
     <artifactId>vaadin-client-compiled</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>com.vaadin</groupId> 
     <artifactId>vaadin-themes</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>com.vaadin.addon</groupId> 
     <artifactId>vaadin-charts-model</artifactId> 
     <version>3.2.0</version> 
    </dependency> 

    <dependency> 
     <groupId>com.vaadin.addon</groupId> 
     <artifactId>vaadin-charts</artifactId> 
     <version>3.2.0</version> 
    </dependency> 

    <dependency> 
     <groupId>batik</groupId> 
     <artifactId>batik-bridge</artifactId> 
     <version>1.6</version> 
    </dependency> 

    <dependency> 
     <groupId>batik</groupId> 
     <artifactId>batik-gvt</artifactId> 
     <version>1.6</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.xmlgraphics</groupId> 
     <artifactId>batik-anim</artifactId> 
     <version>1.8</version> 
    </dependency> 

    <dependency> 
     <groupId>com.lowagie</groupId> 
     <artifactId>itext</artifactId> 
     <version>2.1.7</version> 
    </dependency> 

    <dependency> 
     <groupId>org.vaadin.addon</groupId> 
     <artifactId>confirmdialog</artifactId> 
     <version>3.1.1</version> 
    </dependency> 

    <dependency> 
     <groupId>batik</groupId> 
     <artifactId>batik-util</artifactId> 
     <version>1.6</version> 
    </dependency> 

    <dependency> 
     <groupId>batik</groupId> 
     <artifactId>batik-svggen</artifactId> 
     <version>1.6</version> 
    </dependency> 

    <dependency> 
     <groupId>batik</groupId> 
     <artifactId>batik-svg-dom</artifactId> 
     <version>1.6</version> 
    </dependency> 

    <dependency> 
     <groupId>com.vaadin</groupId> 
     <artifactId>vaadin-client-compiled</artifactId> 
     <version>${vaadin.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>batik</groupId> 
     <artifactId>batik-dom</artifactId> 
     <version>1.6</version> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>5.2.1.Final</version> 
    </dependency> 

    <dependency> 
     <groupId>org.snmp4j</groupId> 
     <artifactId>snmp4j</artifactId> 
     <version>2.5.0</version> 
    </dependency> 

    <dependency> 
     <groupId>ch.ethz.ganymed</groupId> 
     <artifactId>ganymed-ssh2</artifactId> 
     <version>262</version> 
    </dependency> 

</dependencies> 

<build> 
    <plugins> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.6</version> 
      <configuration> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
       <!-- Exclude an unnecessary file generated by the GWT compiler. --> 
       <packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>com.vaadin</groupId> 
      <artifactId>vaadin-maven-plugin</artifactId> 
      <version>${vaadin.plugin.version}</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>update-theme</goal> 
         <goal>update-widgetset</goal> 
         <goal>compile</goal> 
         <goal>compile-theme</goal> 
         <!-- Comment out compile-theme goal to use on-the-fly theme compilation --> 
         <goal>compile-theme</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-clean-plugin</artifactId> 
      <version>3.0.0</version> 
      <!-- Clean up also any pre-compiled themes --> 
      <configuration> 
       <filesets> 
        <fileset> 
         <directory>src/main/webapp/VAADIN/themes</directory> 
         <includes> 
          <include>**/styles.css</include> 
          <include>**/styles.scss.cache</include> 
         </includes> 
        </fileset> 
       </filesets> 
      </configuration> 
     </plugin> 

     <!-- The Jetty plugin allows us to easily test the development build by 
      running jetty:run on the command line. --> 
     <plugin> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-maven-plugin</artifactId> 
      <version>${jetty.plugin.version}</version> 
      <configuration> 
       <scanIntervalSeconds>2</scanIntervalSeconds> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 


<profiles> 
    <profile> 
     <!-- Vaadin pre-release repositories --> 
     <id>vaadin-prerelease</id> 
     <activation> 
      <activeByDefault>false</activeByDefault> 
     </activation> 

     <repositories> 
      <repository> 
       <id>vaadin-prereleases</id> 
       <url>http://maven.vaadin.com/vaadin-prereleases</url> 
      </repository> 


      <repository> 
       <id>vaadin-addons</id> 
       <url>http://maven.vaadin.com/vaadin-addons</url> 
      </repository> 


      <repository> 
       <id>vaadin-snapshots</id> 
       <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url> 
       <releases> 
        <enabled>false</enabled> 
       </releases> 
       <snapshots> 
        <enabled>true</enabled> 
       </snapshots> 
      </repository> 
     </repositories> 
     <pluginRepositories> 
      <pluginRepository> 
       <id>vaadin-prereleases</id> 
       <url>http://maven.vaadin.com/vaadin-prereleases</url> 
      </pluginRepository> 
      <pluginRepository> 
       <id>vaadin-snapshots</id> 
       <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url> 
       <releases> 
        <enabled>false</enabled> 
       </releases> 
       <snapshots> 
        <enabled>true</enabled> 
       </snapshots> 
      </pluginRepository> 
     </pluginRepositories> 
    </profile> 
</profiles> 

而且我的persistence.xml

<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
     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="Test" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> 
    <properties> 
     <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/stabilitydb2?useSSL=false"/> 
     <property name="javax.persistence.jdbc.user" value="root"/> 
     <property name="javax.persistence.jdbc.password" value="PASSWORD_ON_STACKOVERFLOW"/> 
     <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> 
     <property name="hibernate.show_sql" value="false"/> 
     <property name="hibernate.format_sql" value="true"/> 
     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/> 
     <property name="hibernate.hbm2ddl.auto" value="validate"/> 

     <!-- Configuring Connection Pool --> 
     <property name="hibernate.c3p0.min_size" value="5"/> 
     <property name="hibernate.c3p0.max_size" value="20"/> 
     <property name="hibernate.c3p0.timeout" value="500"/> 
     <property name="hibernate.c3p0.max_statements" value="50"/> 
     <property name="hibernate.c3p0.idle_test_period" value="2000"/> 
    </properties> 
</persistence-unit> 

而且我保證persistence.xml中是位於資源

Resources folder

雖然我不斷收到錯誤

Jun 07, 2017 9:58:52 AM com.vaadin.server.DefaultErrorHandler doDefault 
SEVERE: javax.persistence.PersistenceException: No Persistence provider for EntityManager named Test 

和創建EntityManager的代碼(我知道這不是線程安全的 - SRY)。這是在所有其他工作

public class FactoryMaker { 

    /** 
    * The entity manager factory. 
    */ 
    private static EntityManagerFactory entityManagerFactory; 

    /** 
    * Gets the factory - singleton 
    * 
    * @return the factory 
    */ 
    public static EntityManagerFactory getFactory() { 
     if (entityManagerFactory == null) 
      entityManagerFactory = Persistence.createEntityManagerFactory("Test"); 

     return entityManagerFactory; 
    } 

} 

項目。到底是怎麼回事?我嘗試刪除我的回購,並重新導入。沒有骰子。

真的希望有人能幫助我。

此致敬禮。

+1

該文件是否真的有後綴「XML」(首都)?也許修復 –

+0

試過。假設intellij糾正將其改爲大寫字母。剛剛檢查過我的舊項目,都是資信,工作正常。 –

回答

0

這是尷尬的。

的問題是使用mysql-connector ...

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> 
<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>5.1.6</version> 
</dependency> 

失蹤了。

+0

與MqSql數據庫的所有數據庫連接都需要mysql連接器,而不考慮JPA/JDBC。 –

相關問題