所以我試圖建立使用Wildfly,JPA,Hibernate和MariaDB的使用Maven在Eclipse的adminsystem。我在WildFly管理控制檯中配置了我的數據源,一切正常。 Succesful connection picture in WildFly 現在我試圖寫入該項目與實體管理器工廠的數據庫在Eclipse。但我有此錯誤消息: Error message in Eclipse 在這裏你可以看到我的項目樹: Project treepersistence.xml文件是不是在classpath
這裏是我的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>com.gyurmatag.adminsystem</groupId>
<artifactId>adminsystem</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<servlet.version>3.1.0</servlet.version>
<jsf.version>2.2.12</jsf.version>
<primefaces.version>5.3</primefaces.version>
<version.wildfly>9.0.2.Final</version.wildfly>
<jboss.home>${project.build.directory}/wildfly-${version.wildfly}
</jboss.home>
<server.config>standalone.xml</server.config>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<maven-dependency-plugin>2.10</maven-dependency-plugin>
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
<wildfly-maven-plugin.version>1.1.0.Alpha5</wildfly-maven-plugin.version>
</properties>
<dependencies>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<!-- JSF -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf.version}</version>
<scope>compile</scope>
</dependency>
<!-- PrimeFaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>${primefaces.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-
client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.12.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-
entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.12.Final</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<!-- Unpack the distribution -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
<executions>
<execution>
<id>unpack-wildfly</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>${version.wildfly}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}
</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- Copy server configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
<executions>
<execution>
<id>copy-standalone-xml</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jboss.home}/standalone/configuration</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Maven WildFly plugin -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${wildfly-maven-plugin.version}</version>
<configuration>
<jbossHome>${jboss.home}</jbossHome>
<serverConfig>${server.config}</serverConfig>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
這裏是我的持久性。 XML:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/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">
<persistence-unit name="adminsystem" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>jboss/MariaDBDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.connection.release_mode" value="auto" />
</properties>
</persistence-unit>
這裏是我JPAUtility類:
package com.gyurmatag.adminsystem.model;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class JPAUtility {
private static final EntityManagerFactory emFactory;
static {
emFactory = Persistence.createEntityManagerFactory("adminsystem");
}
public static EntityManager getEntityManager(){
return emFactory.createEntityManager();
}
public static void close(){
emFactory.close();
}
}
如果你想採取一個更仔細看看我的項目,你可以在這裏找到:Bitbucket repo
你能幫助我有了這個?
非常感謝! :)
'persistence.xml'就是它應該被稱爲... – DN1
這似乎是一個在問題中錯字... –
是的。這是一個錯字。感謝您的答案! –