hibernate4 测试报错

dml124 发布于 2012/09/01 22:09
阅读 4K+
收藏 0

我写了一个测试的例子不知道为什么会报错,大家帮我看看这是程序的目录结构

配置文件.hbm.xml文件如下图

,hibernate.cfg.xml的配置如下

测试代码如下

package com.mange.po;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;

import com.mange.po.User;


public class Tesr {
	public static void  main(String args[]){
		SessionFactory sf = new Configuration().configure().buildSessionFactory();
		            //打开一个Session
		            Session session = sf.openSession();
		            //开始一个事务
		            Transaction tx = session.beginTransaction();
		            //创建一个Student对象
		            User stu = new User();
		            //通过Student的setter方法改变它的属性
		            //注意student_id不用我们设置
		            stu.setEmail("dml124@163.com");
		            stu.setPass("123456");
		            stu.setUser("lisi");
		            //通过session的save()方法将Student对象保存到数据库中
		            session.save(stu);
		            //提交事务
		            tx.commit();
		            //关闭会话
		            session.close();

	}
	
}

运行后就报错如下

2012-9-1 21:44:07 org.hibernate.annotations.common.Version <clinit>

INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}

2012-9-1 21:44:07 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {4.1.2.Final}

2012-9-1 21:44:07 org.hibernate.cfg.Environment <clinit>

INFO: HHH000206: hibernate.properties not found

2012-9-1 21:44:07 org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist

2012-9-1 21:44:07 org.hibernate.cfg.Configuration configure

INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml

2012-9-1 21:44:08 org.hibernate.cfg.Configuration getConfigurationInputStream

INFO: HHH000040: Configuration resource: /hibernate.cfg.xml

2012-9-1 21:44:09 org.hibernate.cfg.Configuration addResource

INFO: HHH000221: Reading mappings from resource: User.hbm.xml

Exception in thread "main" org.hibernate.MappingNotFoundException: resource: User.hbm.xml not found

at org.hibernate.cfg.Configuration.addResource(Configuration.java:728)

at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2106)

at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2078)

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2058)

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2011)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1926)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1905)

at com.mange.po.Tesr.main(Tesr.java:10)

那位高手给指点指点?

加载中
0
dml124
dml124
自己回答自己了,我找到问题了。错误是这个<mapping resource="com/gc/vo/Custom.hbm.xml"/>应该把包名全部写上,用斜杠分开
JFinal
JFinal
JFinal ActiveRecord 在此: http://www.oschina.net/p/jfinal
0
红薯
红薯
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: User.hbm.xml not found
dml124
dml124
呵呵谢谢红薯这么早就能关注到,我找到问题了。错误是这个<mapping resource="com/gc/vo/Custom.hbm.xml"/>应该把包名全部写上,用斜杠分开
返回顶部
顶部