Java Maven和Hibernate JPA项目错误

Java Maven和Hibernate JPA项目错误,java,hibernate,maven,jpa,Java,Hibernate,Maven,Jpa,当我在ApacheMaven中构建HibernateJPA映射时,我遇到了一个错误 Description Resource Path Location Type The persistence.xml file does not have supported content for this JPA platform. persistence.xml /LearningManagementService/src/main/resources/META-INF JPA Problem 我

当我在ApacheMaven中构建HibernateJPA映射时,我遇到了一个错误

Description Resource Path Location Type
The persistence.xml file does not have supported content for this JPA 
platform.   persistence.xml /LearningManagementService/src/main/resources/META-INF JPA Problem
我的src/main/java有一个com.ph.depd.model包

User.java

package com.ph.deped.model;


/**
* User generated by hbm2java
*/
 public class User implements java.io.Serializable {

/**
 * 
 */
private static final long serialVersionUID = -2357935130826100477L;
private long id;
private Privilege privilege;
private String username;
private String password;

public User() {
}

public User(Privilege privilege, String username, String password) {
    this.privilege = privilege;
    this.username = username;
    this.password = password;
}

public long getId() {
    return this.id;
}

public void setId(long id) {
    this.id = id;
}

public Privilege getPrivilege() {
    return this.privilege;
}

public void setPrivilege(Privilege privilege) {
    this.privilege = privilege;
}

public String getUsername() {
    return this.username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return this.password;
}

public void setPassword(String password) {
    this.password = password;
}

}
Privilege.java

package com.ph.deped.model;
// Generated May 7, 2018 9:04:03 PM by Hibernate Tools 5.2.3.Final

import java.util.HashSet;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * Privilege generated by hbm2java
 */

public class Privilege implements java.io.Serializable {

/**
 * 
 */
private static final long serialVersionUID = 910980850904284147L;
private long id;
private String description;

@JsonIgnore
private Set<User> users = new HashSet<User>(0);

public Privilege() {
}

public Privilege(String description, Set<User> users) {
    this.description = description;
    this.users = users;
}

public long getId() {
    return this.id;
}

public void setId(long id) {
    this.id = id;
}

public String getDescription() {
    return this.description;
}

public void setDescription(String description) {
    this.description = description;
}

public Set<User> getUsers() {
    return this.users;
}

public void setUsers(Set<User> users) {
    this.users = users;
}

}
package com.ph.depd.model;
//由Hibernate Tools 5.2.3.Final于2018年5月7日晚上9:04:03生成
导入java.util.HashSet;
导入java.util.Set;
导入com.fasterxml.jackson.annotation.JsonIgnore;
/**
*hbm2java生成的特权
*/
公共类特权实现java.io.Serializable{
/**
* 
*/
私有静态最终长serialVersionUID=910980850904284147L;
私人长id;
私有字符串描述;
@杰索尼奥雷
私有集用户=新哈希集(0);
公共特权(){
}
公共权限(字符串描述,设置用户){
this.description=描述;
this.users=用户;
}
公共长getId(){
返回此.id;
}
公共无效集合id(长id){
this.id=id;
}
公共字符串getDescription(){
返回此.description;
}
公共void集合描述(字符串描述){
this.description=描述;
}
公共集getUsers(){
将此文件返回给用户;
}
公共void集合用户(集合用户){
this.users=用户;
}
}
然后,我的hbm.xml映射位于src/main/resources中,其包com.ph.depd.model与实体对象相同

User.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-access="property" default- 
cascade="none" default-lazy="true">
<class catalog="elearning" dynamic-insert="false" dynamic-update="false" mutable="true" name="com.ph.deped.model.User" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="user">
    <id name="id" type="long">
        <column name="id"/>
        <generator class="identity"/>
    </id>
    <many-to-one class="Privilege" embed-xml="true" fetch="select" insert="true" name="privilege" not-found="exception" optimistic-lock="true" unique="false" update="true">
        <column name="privilege_id"/>
    </many-to-one>
    <property generated="never" lazy="false" name="username" optimistic-lock="true" type="string" unique="false">
        <column name="username"/>
    </property>
    <property generated="never" lazy="false" name="password" optimistic-lock="true" type="string" unique="false">
        <column name="password"/>
    </property>
</class>
</hibernate-mapping>

Privilege.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-access="property" default- 
cascade="none" default-lazy="true">
<class catalog="elearning" dynamic-insert="false" dynamic-update="false" mutable="true" name="com.ph.deped.model.Privilege" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="privilege">
    <id name="id" type="long">
        <column name="id"/>
        <generator class="identity"/>
    </id>
    <property generated="never" lazy="false" name="description" optimistic-lock="true" type="string" unique="false">
        <column name="description"/>
    </property>
    <set embed-xml="true" fetch="select" inverse="true" lazy="true" mutable="true" name="users" optimistic-lock="true" sort="unsorted" table="user">
        <key on-delete="noaction">
            <column name="privilege_id"/>
        </key>
        <one-to-many class="User" embed-xml="true" not-found="exception"/>
    </set>
</class>
</hibernate-mapping>

最后,我的persistence.xml位于src/main/resources下的META-INF/persistence.xml

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_1_1.xsd" 
version="1.1">

<persistence-unit name="Elearning" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <mapping-file>/com/ph/deped/model/UserLogin.hbm.xml</mapping-file>
    <mapping-file>/com/ph/deped/model/Privilege.hbm.xml</mapping-file>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.user" value="root"/>
        <property name="javax.persistence.jdbc.password" value="1a0b1c6d0d6c1b3aA@"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.enable_lazy_load_no_trans" value="true"/>
        <property name="hibernate.show_sql" value="false"/>
    </properties>
</persistence-unit>

</persistence>

org.hibernate.ejb.HibernatePersistence
/com/ph/depd/model/UserLogin.hbm.xml
/com/ph/depd/model/Privilege.hbm.xml

看看为什么要使用
persistence.xml
?你在学习过时的教程吗?过时了吗?那么,如果persistence.xml已经过时,那么新的实现是什么呢。。