Topic: [求助]Error reading resource问题。

  Print this page

1.[求助]Error reading resource问题。 Copy to clipboard
Posted by: David0203
Posted on: 2004-12-27 14:41

做了一个hibernate的demo。
在web-INF下classes下建了hibernate.cfg.xml,Address.hbm.xml,Classes.hbm.xml,Students.hbm.xml文件,运行的时候提示
exception

javax.servlet.ServletException: Error reading resource: Students.hbm.xml
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
  org.apache.jsp.index_jsp._jspService(index_jsp.java:69)
  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)

hibernate.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory >

    <!-- local connection properties -->
    <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password"></property>
    <!-- property name="hibernate.connection.pool_size"></property -->

    <!-- dialect for MySQL -->
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<!-- mapping files -->
<mapping resource="Students.hbm.xml"/>
<mapping resource="Classes.hbm.xml"/>
<mapping resource="Courses.hbm.xml"/>
<mapping resource="Address.hbm.xml"/>

</session-factory>
</hibernate-configuration>

Students.hbm.xml:
<?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="Hibernate.Students" table="students">
    <id
      column="StudentId"
      name="Id"
      type="string"
    >
      <generator class="assigned" />
    </id>
    <property
      column="ClassesId"
      length="32"
      name="ClassesId"
      not-null="true"
      type="string"
     />
    <property
      column="name"
      length="32"
      name="Name"
      not-null="false"
      type="string"
     />
     <!-- 描述Student和Course多对多的关系-->
<set
name="courses"
table="Student_Course_Link"
lazy="false"
inverse="false"
cascade="all"
sort="unsorted"
>

<key
column="StudentId"
/>

<many-to-many
class="Hibernate.Course"
column="CourseId"
outer-join="auto"
/>
</set>
  <!-- 描述Student和Classes之间多对一的关系-->
<many-to-one
name="classes"
class="Hibernate.Classes"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ClassesId"
/>

<!-- 描述Student和Address之间一对一的关系-->
<one-to-one
name="address"
class="Hibernate.Address"
cascade="none"
outer-join="auto"
constrained="false"
/>
    
  </class>
</hibernate-mapping>

2.Re:[求助]Error reading resource问题。 [Re: David0203] Copy to clipboard
Posted by: getup
Posted on: 2005-01-18 09:27

你用的编译工具是什么啊?
一般来说,需要两个条件:
1。应该在src目录下放置那几个hbm文件;
2。配置编译环境,在编译的时候让编译工具自己把hbm文件复制到class下
如果没有这两个条件,编译的时候,编译工具可能会清空class下的所有文件,再重新生成,运行的时候hbm文件就没有了。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923