David0203
发贴: 7
积分: 0
|
于 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>
David0203 edited on 2004-12-27 16:32
|