Hibernate org.Hibernate.MappingException:未知实体

Hibernate org.Hibernate.MappingException:未知实体,hibernate,Hibernate,由于某种原因,我无法映射以下实体,并且在运行时得到“org.hibernate.MappingException:Unknown entity” 人: package abo; public class Human { private int id; private String name; public Human() { } public int getId() { return id; } public void setId(int id) { this.id =

由于某种原因,我无法映射以下实体,并且在运行时得到“org.hibernate.MappingException:Unknown entity”

人:

package abo;

public class Human {

private int id;
private String name;
public Human()
{

}

public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}

}
映射文件Human.hbm.xml(在同一个包中):


现在是hibernate配置文件(hibernate.cfg.xml):


com.mysql.jdbc.Driver
布拉布拉
jdbc:mysql://localhost:3306
根
蛋白质跟踪器
org.hibernate.dialogue.mysqldialogue
有什么建议吗?
谢谢

如何获取ServiceRegistry和SessionFactory实例

我也犯了同样的错误,但当我尝试这个方法时,它是有效的:

ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();

SessionFactory sessionFactory = new MetadataSources( serviceRegistry ).buildMetadata().buildSessionFactory();
我从你那里得到这个


我正在研究一个类似于你的例子。我希望这对你有帮助

如何获取ServiceRegistry和SessionFactory实例

我也犯了同样的错误,但当我尝试这个方法时,它是有效的:

ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();

SessionFactory sessionFactory = new MetadataSources( serviceRegistry ).buildMetadata().buildSessionFactory();
我从你那里得到这个


我正在研究一个类似于你的例子。我希望这对你有帮助

尝试将示例SessionFactory编写为:

SessionFactory objSf = new Configuration().configure().buildSessionFactory();

尝试将示例SessionFactory编写为:

SessionFactory objSf = new Configuration().configure().buildSessionFactory();

您需要将@Entity放在Human类之上,以便让Hibernate知道要映射它。您还需要将包路径和类名添加到配置文件中。比如:

您的Human类上方需要@Entity来让Hibernate知道要映射它。您还需要将包路径和类名添加到配置文件中。比如: