Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate和MappingNotFoundException_Java_Xml_Hibernate_Mapping - Fatal编程技术网

Java Hibernate和MappingNotFoundException

Java Hibernate和MappingNotFoundException,java,xml,hibernate,mapping,Java,Xml,Hibernate,Mapping,我使用netbeanside 我的hibernate.cfg.xml如下所示: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

我使用netbeanside

我的hibernate.cfg.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    //properties

    <mapping resource="entities.Employee"/>
    <mapping resource="entities.Human"/>
  </session-factory>
</hibernate-configuration>
static {
    try { 
        String configFilePath = "/hibernate.cfg.xml";
        URL configFileURL = SessionFactory.class.getResource(configFilePath);
        sessionFactory = new Configuration().configure(configFileURL).buildSessionFactory();
    } catch (Throwable ex) {
        // Log the exception. 
        throw new RuntimeException(ex);
    }
}
初始化SessionFactory的代码如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    //properties

    <mapping resource="entities.Employee"/>
    <mapping resource="entities.Human"/>
  </session-factory>
</hibernate-configuration>
static {
    try { 
        String configFilePath = "/hibernate.cfg.xml";
        URL configFileURL = SessionFactory.class.getResource(configFilePath);
        sessionFactory = new Configuration().configure(configFileURL).buildSessionFactory();
    } catch (Throwable ex) {
        // Log the exception. 
        throw new RuntimeException(ex);
    }
}
并且实体(Employee.class和Human.class)在

班级员工:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@Table(name = "EMPLOYEE")
public class Employee implements Serializable {

    public Employee(){
    }

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    @Column(name = "EMPLOYEE_ID")
    private int employeeId;

    @Column(name = "SALARY")
    private double salary;

    @OneToOne(cascade = CascadeType.ALL, fetch= FetchType.LAZY)
    @PrimaryKeyJoinColumn
    private Human humDate;

    public int getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(int employeeId) {
        this.employeeId = employeeId;
    }

    public Human getHumDate() {
        return humDate;
    }

    public void setHumDate(Human humDate) {
        this.humDate = humDate;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

}
类人:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    package entities;

    import java.io.Serializable;
    import javax.persistence.*;

    @Entity
    @Table(name = "HUMAN")
    public class Human implements Serializable {

        public Human(){
        }

        public Human(String name){
            this.name = name;
        }

        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.TABLE)
        private int id;

        @Column(name = "HUM_NAME")
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getId() {
            return id;
        }

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

        @Override
        public int hashCode() {
            int hash = 0;
            hash += (int) id;
            return hash;
        }

        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Human)) {
                return false;
            }
            Human other = (Human) object;
            if (this.id != other.id) {
                return false;
            }
            return true;
        }

        @Override
        public String toString() {
            return "com.nsn.Human[ id=" + id + " ]";
        }

    }
这里怎么了?

您应该使用
而不是


用于使用
.hbm.xml
文件而不是注释进行映射。

您应该使用
而不是



用于使用
.hbm.xml
文件而不是注释进行映射。

您需要提供更多信息,似乎您没有正确注释或映射它们,您可以添加类和映射吗?您需要提供更多信息,似乎您没有正确注释或映射它们,您可以添加类和映射吗?
<mapping class = "entities.Employee" />
<mapping class = "entities.Human" />