org.hibernate.boot.InvalidMappingException怎么解决

qq_23328379 2016-03-29 08:47:59

当运行测试程序时,出现了下面的异常,是什么回事?Exception in thread "main" org.hibernate.boot.InvalidMappingException: Could not parse mapping document: com/bjsxt/hibernate/model/student.hbm.xml (RESOURCE)
具体文档如下:
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 package="com.bjsxt.hibernate.model">
<class name="Student">
<id name="id" > </id>
<property name="name"></property>
<propety name="age"></propety>
</class>

</hibernate-mapping>

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.bjsxt.hibernate.model.Student;


public class StudentTest {

public static void main(String[] args){

Student s= new Student();
s.setId(1);
s.setName("s1");
s.setAge(1);

Configuration cfg=new Configuration();
SessionFactory sf=cfg.configure().buildSessionFactory();
Session session=sf.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
sf.close();
}
}

package com.bjsxt.hibernate.model;

public class Student {

private int id;
private String name;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">liulei</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<!-- <property name="current_session_context_class">thread</property> -->

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<!--<property name="hbm2ddl.auto">update</property>
-->
<mapping resource="com/bjsxt/hibernate/model/student.hbm.xml"/>

</session-factory>

</hibernate-configuration>
...全文
245 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_23328379 2016-03-30
  • 打赏
  • 举报
回复
找到问题了,是hbm.xml文件中property写错了
bobolnear 2016-03-30
  • 打赏
  • 举报
回复
查下 发布的项目中是否有 student.hbm.xml 这个文件,检查下是否缓存问题。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧