所以我正在研究我的毕业设计,我遇到了这个问题:
Exception in thread "main" java.lang.ExceptionInInitializerError: Initial SessionFactory failedorg.hibernate.boot.InvalidMappingException: Could not parse mapping document: Beans/Receptions.hbm.xml (RESOURCE)
at Logic.HibernateSessionFactory.buildSessionFactory(HibernateSessionFactory.java:25)
at Logic.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:10)
at Main.main(Main.java:7)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
使用退出代码1完成处理
Receptions.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>
<class name="Beans.Receptions" table="receptions" schema="diplomdb">
<id name="recNum">
<column name="recNum" sql-type="int(11)"/>
</id>
<property name="docPass">
<column name="docPass" sql-type="int(11)"/>
</property>
<property name="regNum">
<column name="regNum" sql-type="int(11)"/>
</property>
<property name="recDate">
<column name="recDate" sql-type="date"/>
</property>
</class>
</hibernate-mapping>
Receptions.java:
package Beans;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.sql.Date;
@Entity
public class Receptions {
private int recNum;
private int docPass;
private int regNum;
private Date recDate;
@Id
@Column(name = "recNum", nullable = false)
public int getRecNum() {
return recNum;
}
public void setRecNum(int recNum) {
this.recNum = recNum;
}
@Basic
@Column(name = "docPass", nullable = false)
public int getDocPass() {
return docPass;
}
public void setDocPass(int docPass) {
this.docPass = docPass;
}
@Basic
@Column(name = "regNum", nullable = false)
public int getRegNum() {
return regNum;
}
public void setRegNum(int regNum) {
this.regNum = regNum;
}
@Basic
@Column(name = "recDate", nullable = false)
public Date getRecDate() {
return recDate;
}
public void setRecDate(Date recDate) {
this.recDate = recDate;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Receptions that = (Receptions) o;
if (recNum != that.recNum) return false;
if (docPass != that.docPass) return false;
if (regNum != that.regNum) return false;
if (recDate != null ? !recDate.equals(that.recDate) : that.recDate != null) return false;
return true;
}
@Override
public int hashCode() {
int result = recNum;
result = 31 * result + docPass;
result = 31 * result + regNum;
result = 31 * result + (recDate != null ? recDate.hashCode() : 0);
return result;
}
}
POJO类和映射文件是由IDEA生成的,但它一直说它无法解析文件。 我的项目结构看起来像this
你可以给我一些提示吗?我不明白它有什么问题,映射文件对我来说很好看答案 0 :(得分:0)
在此设置中,有两件事我很奇怪: a)为什么在实体上同时具有映射xml和带注释的映射?似乎多余/不正确。新版本的hibernate倾向于消除对xml配置文件的需求。
b)在你的xml上,这个&#34;类名=&#34; Beans.Receptions&#34;看起来不对劲如果hbm文件在包本身内,它不应该需要前缀,我试试用#34; class name =&#34; Receptions&#34;