日期:2014-05-17  浏览次数:20702 次

hibernate 中配置问题 请大神指点一二
这是我的Student.hbm.xml
<?xml version="1.0" encoding='UTF-8'?> 
<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-mapping package="com.bjsxt.hibernate.model">
<class name="Student" table="Student">
<id name="id" column="id" type="integer"></id>
<property name="name"></property>
<property name="age"></property>
</class>
</hibernate-mapping>

报错Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/bjsxt/hibernate/model/Student.hbm.xml
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
Caused by: org.xml.sax.SAXParseException: Element type "hibernate-mapping" must be declared.

------解决方案--------------------
<property name="name"></property>
<property name="age"></property>

这两句没写column
------解决方案--------------------
我的Student.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 >

<class name="com.hibernate.Student" table="Student">
<id name="sid" column="ID_">
<generator class="native"/>
</id>
<property name="uname" />
<property name="age"/>


</class>

 

</hibernate-mapping>

------解决方案--------------------
是不是你的Student.hbm.xml文件和你的Student类里面的属性不匹配。。让eclipse无法解析通过。。。
------解决方案--------------------
是不是hibernate,cfg.xml中没有
<mapping resource="../Student.hbm.xml"/>
------解决方案--------------------
贴出你hiberenate的配置文件出来。。。。