Hibernate不能从资源文件解析映射

这两天,遇到这么一个问题,Hibernate不能从资源文件解析映射,报错如下:
  

Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource wei/college/bean/personMessages.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:523)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1511)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
at wei.college.bean.CreateTable.main(CreateTable.java:8)
Caused by: org.hibernate.PropertyNotFoundException: field [contents;] not found on wei.college.bean.PersonMessages
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:112)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:119)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:127)
at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:83)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:71)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2164)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2141)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2031)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:424)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:465)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:520)
... 7 more


为了验证我的其它配置文件是否有问题,我把personMessages.hbm.xml的映射从我的hibernate.cfg.xml去除,只映射person.hbm.xml却成功创建了person表。根据在谷歌所搜到的,基本是先检查是否导包,头<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">是否弄错呀,id主键生配置等。但如果这些有问题,我之前的person表不可能创建成功吧。想来想去一定是我的personMessages.hbm.xml配置有问题。但我找了半天,还是没找到。
  这让我的进度到了这就戛然而止,这让我很是郁闷,如果有人能看到这帖子,帮我一下,看出是什么问题不。谢谢指点!我把相关配置贴出如下:
1.hibernate.cfg.xml:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/college
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="myeclipse.connection.profile">mysql</property>
<mapping resource="wei/college/bean/person.hbm.xml" />
<mapping resource="wei/college/bean/personMessages.hbm.xml" />
</session-factory>
</hibernate-configuration>

2.personMessages.hbm.xml:

 <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="wei.college.bean">
<!-- 个人用户相关信息 -->
<class name="PersonMessages">
<id name="id" type="integer">
<generator class="native"></generator>
</id>
<property name="realname"></property>
<property name="sex"></property>
<property name="birthday"></property>
<property name="age"></property>
<property name="height"></property>
<property name="weight"></property>
<property name="national"></property>
<property name="marital"></property>
<property name="address"></property>
<property name="degree"></property>
<property name="department"></property>
<property name="professional"></property>
<property name="political"></property>
<property name="certificateType"></property>
<property name="certificateNum"></property>
<property name="email"></property>
<property name="phone"></property>
<property name="interest"></property>
<property name="contents;"></property>
<property name="imageUrl"></property>
<one-to-one name="person" class="Person"></one-to-one>
</class>
</hibernate-mapping>

3.personMessages.java:

package wei.college.bean;
public class PersonMessages {
private Person person;//个人用户
private int id;//ID
private String realname;//真实姓名
private String sex;//性别
private String birthday;//生日
private int age;//年龄
private String height;//身高
private String weight;//体重
private String national;//民族
private String marital;//婚姻状况
private String address;//地址
private String degree;//学历
private String department;//系别
private String professional;//专业
private String political;//政治面貌
private String certificateType;//证件类型
private String certificateNum;//证件号码
private String email;//Email
private String phone;//手机号码
private String interest;//兴趣爱好
private String contents;//自我描述
private String imageUrl;//头像

//set和get方法省略......
}

4.CreateTabel.java:

package wei.college.bean;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class CreateTable {
public static void main(String[] args) {
Configuration conf = new Configuration().configure();
SchemaExport se = new SchemaExport(conf);
se.create(true, true);
}
}


以上所需要jar包均导入,并只要在hibernate.cfg.xml文件中删除掉
<mapping resource="wei/college/bean/personMessages.hbm.xml" />就可以成功创建person表
其中person.hbm.xml配置如下:

 <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="wei.college.bean">
<!--个人用户 -->
<class name="Person" >
<id name="id" type="integer">
<generator class="native"></generator>
</id>
<property name="username"></property>
<property name="password"></property>
<property name="email"></property>
<one-to-one name="personMess" class="PersonMessages" ></one-to-one>
</class>
</hibernate-mapping>


如果有出现这样问题的请帮忙指点一下是什么原因,应该如何更改才能解决呢!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值