|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2004-08-20
小弟刚开始接触hibernate,遇到自己难以解决的问题,各位帮帮我,谢谢!
运行环境:tomcat5,连接池测试成功。数据库mySql4.0.20,按照文档手工建表CAT。 cat_id varchar(32) key not null name varchar(16) not null sex char(1) weight double cat.java和hibernate.cfg.xml这些都是完全按照文档写的。 Cat.hbm.xml文件 [code:1] <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="net.sf.hibernate.examples.quickstart.Cat" table="CAT"> <id name="id" type="string" unsaved-value="null" > <column name="CAT_ID" sql-type="varchar(32)" notnull="true"/> <generator class="uuid.hex"/> </id> <property name="name"> <column name="NAME" sql-type="varchar(16)" notnull="true"/> </property> <property name="sex"/> <property name="weight"/> </class> </hibernate-mapping> [/code:1] cat.jsp测试文件 [code:1] <%@ page contentType="text/html;charset=gb2312"%> <%@ page import="net.sf.hibernate.Session"%> <%@ page import="net.sf.hibernate.Transaction"%> <%@ page import="net.sf.hibernate.SessionFactory"%> <%@ page import="net.sf.hibernate.cfg.Configuration"%> <%@ page import="cn.com.test.Cat"%> <%! net.sf.hibernate.Session s=null; net.sf.hibernate.Transaction tx= null; Cat princess =null; %> <% //System.out.println(" 程序开始…… "); SessionFactory sessionFactory =new Configuration().configure().buildSessionFactory(); s = sessionFactory.openSession(); //System.out.println(" session创建成功"); tx= s.beginTransaction(); //System.out.println(" Transaction创建成功"); princess = new Cat(); princess.setName("Princess"); princess.setSex('F'); princess.setWeight(7.4f); s.save(princess); tx.commit(); s.close(); System.out.println(" 数据写入成功!"); %> [/code:1] 报错信息: [code:1] exception javax.servlet.ServletException: Error reading resource: Cat.hbm.xml org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800) org.apache.jsp.cat_jsp._jspService(cat_jsp.java:88) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) root cause net.sf.hibernate.MappingException: Error reading resource: Cat.hbm.xml net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:318) net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:976) net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:928) net.sf.hibernate.cfg.Configuration.configure(Configuration.java:856) net.sf.hibernate.cfg.Configuration.configure(Configuration.java:842) org.apache.jsp.cat_jsp._jspService(cat_jsp.java:62) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) [/code:1] 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
时间:2004-08-21
我后来用Middlegen又重新生成了Cat.hbm.xml,用hbm2java生成Cat.java,这两个文件应该是没什么问题,最后运行测试jsp文件还是一样的报错!!我都晕死了!!第一次用hibernate就出师不利啊!!谁帮帮我啊!!多谢了!!!!
|
|
| 返回顶楼 | |
|
时间:2004-08-22
应该是jsp写的有些问题,SessionFactory不能做为实例变量。
|
|
| 返回顶楼 | |
|
时间:2004-08-22
应该是找不到Cat.hbm.xml 文件
如果hibernate.cfg.xml中没有指定Cat.hbm.xml 的路径,放到classpath. 如WEB-INF/classes |
|
| 返回顶楼 | |
|
时间:2004-08-23
不是路径问题,Cat.hbm.xml就是在WEB-INF/classes下。而且我查了一下hibernate源码,记得专门有一个针对hbm.xml文件的not found异常。谢谢!
|
|
| 返回顶楼 | |
|
时间:2004-08-23
看不出什么问题,但配置好log4j,logger级别设为debug的话应该能看出一些原因
|
|
| 返回顶楼 | |
|
时间:2004-08-30
SessionFactory sessionFactory =new Configuration().configure().addClass(Cat.class);.buildSessionFactory();
|
|
| 返回顶楼 | |
|
时间:2004-09-11
我也记不清是怎么一回事了,不过有一点好像跟hibernate中的数据类型有关我遇到过你看一下是不是它没有float这种类型,应该是它不支持这种类型,你把foat类型换成别的类型
|
|
| 返回顶楼 | |
|
时间:2004-09-11
对不起,我真的给忘记了是什么类型它不支持。但可以确定的是:它并不是完全支持Java里面的所有类型
|
|
| 返回顶楼 | |
|
时间:2004-09-11
我有点不明白,为啥要用jsp来测试,写个TestCase不就好了
|
|
| 返回顶楼 | |






