读书人

hibernate 中配置有关问题 请大神指点

发布时间: 2012-05-15 14:35:29 作者: rapoo

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的配置文件出来。。。。

读书人网 >Java Web开发

热点推荐