我是Hibernate的新手,我正在尝试使用IntelliJ Idea中的Maven在Java中创建一些应用程序。我在上面的标题中遇到了这个错误,Stack上相同问题的答案直到现在才帮助我。
这个文件“Person.hbm.xml”是什么。我必须创建它吗?一旦它是映射资源,Hibernate就不应该自己创建它吗?
当我运行我的小程序时,我收到此错误:
Exception in thread "main" org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found : HibernateExposed/Person.hbm.xml : origin(HibernateExposed/Person.hbm.xml)
at org.hibernate.boot.spi.XmlMappingBinderAccess.bind(XmlMappingBinderAccess.java:56)
at org.hibernate.boot.MetadataSources.addResource(MetadataSources.java:274)
at org.hibernate.boot.cfgxml.spi.MappingReference.apply(MappingReference.java:70)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:412)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:86)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
at Persistencia.HibernateUtils.<init>(HibernateUtils.java:10)
at Main.Main.main(Main.java:16)
这是我的数据库配置类:HibernateUtils:
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtils {
//Fábrica de sessões de banco de dados constante no padrão SINGLETON
SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
}
下面是我试图坚持的实体类:
import javax.persistence.Entity;
import java.sql.Date;
@Entity
public class Produto {
private String nome;
private int cod;
private float valor;
private Date dataValidade;
protected Produto() {
}
public Produto(String nome, int cod, float valor, Date dataValidade) {
this.nome = nome;
this.cod = cod;
this.valor = valor;
this.dataValidade = dataValidade;
}
项目结构,以及休眠.cfg.xml文件的位置。
慕仙森
炎炎设计
相关分类