- 浏览: 1106 次
- 性别:
- 来自: 江苏
文章分类
最新评论
好心人帮忙哈 Could not read mappings from resource
我用struts+hibernate开发一个bbs论坛出现了问题
工具是 Myeclipse+MySql
jdk6.0 tomcat6.0
问题描述:有两个.hbm.xml文件分别是user.hbm.xml和sort.hbm.xml. 与之对应的是两个.java文件User.java和Sort.java.
还有个hibernate.cfg.xml文件
user.hbm.xml和sort.hbm.xml在hibernate包内
hibernate.cfg.xml在hibernate包的上级目录里
以下为正文:
hibernate.cfg.xml文件:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/bookstore</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="myeclipse.connection.profile">MySQL</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<mapping resource="hibernate/user.hbm.xml"/>
<mapping resource="hibernate/sort.hbm.xml"/>
</session-factory>
</hibernate-configuration>
user.hbm.xml文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping >
<class table="bbsuser" name="StudyBbs.User">
<id name="id" column="id">
<generator class="increment"/>
</id>
<property name="username" column="username" type="String"></property>
<property name="password" column="password" type="String"></property>
<property name="nickname" column="nickname" type="String"></property>
<property name="sex" column="sex" type="String"></property>
<property name="birthyear" column="birthyear" type="String"></property>
<property name="birthmonth" column="birthmonth" type="String"></property>
<property name="birthday" column="birthday" type="String"></property>
<property name="email" column="email" type="String"></property>
<property name="mobile" column="mobile" type="String"></property>
<property name="signiture" column="signiture" type="String"></property>
<property name="grade" column="grade" type="String"></property>
<property name="score" column="score" type="Integer"></property>
</class>
</hibernate-mapping>
User.java类:
package StudyBbs;
import java.util.*;
import java.sql.Connection;
import java.sql.ResultSet;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.cfg.*;
import StudyBbsForm.LoginUserForm;
import hibernate.HibernateSessionFactory;
import org.hibernate.Session;
public class User {
private int id;
private String username = null;
private String password = null;
private String nickname = null;
private String sex = null;
private String birthyear = null;
private String birthmonth = null;
private String birthday = null;
private String email = null;
private String mobile = null;
private String signiture = null;
private String grade = null;
private int score = 0;
public User(){}
public void setUsername(String username) {
this.username = username;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getNickname() {
return nickname;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getSex() {
return sex;
}
public void setBirthyear(String birthyear) {
this.birthyear = birthyear;
}
public String getBirthyear() {
return birthyear;
}
public void setBirthmonth(String birthmonth) {
this.birthmonth = birthmonth;
}
public String getBirthmonth() {
return birthmonth;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getBirthday() {
return birthday;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getMobile() {
return mobile;
}
public void setSigniture(String signiture) {
this.signiture = signiture;
}
public String getSigniture() {
return signiture;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getGrade() {
return grade;
}
public void setScore(int score) {
this.score = score;
}
public int getScore() {
return score;
}
public static boolean checkUser(String name,String psw)
throws Exception{
Session session=null;
session=HibernateSessionFactory.getSession();
Transaction trancation=session.beginTransaction();
Query query=session.createQuery("from User as a where a.username='"+name+"' and a.password='"+psw+"'");
Iterator it=query.iterate();
if(it.hasNext()){
return true;
}else{
return false;
}
}
public static String getUserGrade(DB db,String name) throws Exception{
String strSql;
ResultSet rs;
String strHql="from User as u where u.username='"+name+"'";
Iterator it=db.OpenSql(strHql);
if ( it.hasNext()) {
User user=(User)it.next();
return user.getGrade();
}
else{
return null;
}
}
public static Vector Search(DB db ,String username) throws Exception{
Vector Users = new Vector();
ResultSet rs,rsNest;
String strSql=null;
String strHql="from User as u where u.username like '%"+username+"%'";
Iterator it = db.OpenSql(strHql);
while (it.hasNext()){
User u=(User)it.next();
User user = new User();
user.setUsername(u.getUsername()) ;
user.setGrade(u.getGrade()) ;
Users.add(user);
}
return Users;
}
public static Vector SearchMaster(DB db) throws Exception{
Vector Users = new Vector();
ResultSet rs,rsNest;
String strSql=null;
String strHql="from User as u where u.grade='斑竹'";
Iterator it = db.OpenSql(strHql);
while (it.hasNext()){
User u=(User)it.next();
User user = new User();
user.setUsername(u.getUsername()) ;
user.setGrade(u.getGrade()) ;
Users.add(user);
}
return Users;
}
}
sort.hbm.xml文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping >
<class table="sort" name="StudyBbsForm.SortForm">
<id name="id" column="id">
<generator class="increment"/>
</id>
<property name="name" column="sortname" type="String"></property>
<property name="master" column="master" type="String"></property>
</class>
</hibernate-mapping>
Sort.java文件:
package StudyBbs;
import java.util.*;
import java.sql.Connection;
import java.sql.ResultSet;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Transaction;
import hibernate.HibernateSessionFactory;
public class Sort implements java.io.Serializable{
private int id;
private String name;
private String master;
private int topicNum;
private int lastTopicId;
private String lastTopic="";
private String lastTopicOwner="";
private String lastTopicTime="";
public Sort(){}
public Sort(int id,String name,String master,int topicNum,int lastTopicId,String lastTopic,String lastTopicOwner,String lastTopicTime){
this.id = id;
this.name = name;
this.master = master;
this.topicNum = topicNum;
this.lastTopicId = lastTopicId;
this.lastTopic = lastTopic;
this.lastTopicOwner = lastTopicOwner;
this.lastTopicTime = lastTopicTime;
}
public int getId(){
return id;
}
public String getName(){
return name;
}
public String getMaster(){
return master;
}
public int getTopicNum(){
return topicNum;
}
public int getLastTopicId(){
return lastTopicId;
}
public String getLastTopic(){
return lastTopic;
}
public String getLastTopicOwner(){
return lastTopicOwner;
}
public String getLastTopicTime(){
return lastTopicTime;
}
public static Vector Search(DB db) throws Exception{
Vector sorts=new Vector();
Iterator it,topicIt;
int topicNum=0;
int lastTopicId;
String lastTopic;
String lastTopicOwner;
String lastTopicTime;
String strHql;
String countHql;
String master,sortname;
int sortid;
strHql="from Sort order by id desc";
it=db.OpenSql(strHql);
while(it.hasNext()){
lastTopicId =0;
lastTopic=null;
lastTopicOwner=null;
lastTopicTime=null;
Sort sort=(Sort)it.next();
sortid=sort.getId();
master=sort.getMaster();
sortname=sort.getName();
countHql="select count(*) from Topic as a where a.id="+sortid;
topicNum=db.getCount(countHql);
strHql="from Topic as a where a.sortid="+sortid+"order by id desc";
topicIt=db.OpenSql(strHql);
if(topicIt.hasNext()){
Topic topic=(Topic)it.next();
lastTopicId = topic.getId();
lastTopic = topic.getTitle();
lastTopicTime = topic.getTime();
lastTopicOwner = topic.getOwner();
}
sorts.add(new Sort(
sortid,
sortname,
master,
topicNum,
lastTopicId,
lastTopic,
lastTopicTime,
lastTopicOwner
));
}
return sorts;
}
抛出的异常是:
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Could not read mappings from resource: hibernate/sort.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at hibernate.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:30)
at StudyBbs.User.checkUser(User.java:139)
at StudyBbsAction.LoginAction.execute(LoginAction.java:46)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.PropertyNotFoundException: field not found: id
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:97)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:112)
at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:89)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:77)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:410)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:343)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
... 26 more
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Could not read mappings from resource: hibernate/user.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at hibernate.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)
at hibernate.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)
at StudyBbs.User.checkUser(User.java:139)
at StudyBbsAction.LoginAction.execute(LoginAction.java:46)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping StudyBbs.User
at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:154)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
... 27 more
2008-8-11 18:41:20 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at StudyBbs.User.checkUser(User.java:140)
at StudyBbsAction.LoginAction.execute(LoginAction.java:46)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Unknown Source)
急。。。。。希望你们能帮到我,感谢所有看到此贴的人
相关推荐
"Mappings of problems from the book Elements of Programming.zip"这个压缩文件很可能是该书中的问题和练习的映射或解决方案集,旨在帮助读者更好地理解和应用书中所讲解的编程概念。 首先,我们来详细解析一下...
标签:airavata-rest-mappings-0.9-javadoc.jar,airavata,rest,mappings,0.9,javadoc,jar包下载,依赖包
标签:airavata-rest-mappings-0.7.jar,airavata,rest,mappings,0.7,jar包下载,依赖包
标签:airavata-rest-mappings-0.8.jar,airavata,rest,mappings,0.8,jar包下载,依赖包
xsl-mappings
ABAP JSON 字段名映射 name_mappings支持字段名大写,小写,驼峰等。 完整代码,可以直接运行。
"Identity Mappings in Deep Residual Networks"是这个主题的核心,它涉及到了深度神经网络(Deep Neural Networks,DNNs)的设计策略,特别是残差网络(Residual Networks,ResNets)中的一个重要概念。 在传统的...
【迁移到 AndroidX】support库...If you run into issues with migration, refer to these tables to determine the proper mappings from the support library to the corresponding AndroidX artifacts and classes:
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
"SQL-Server-Data-Type-Mappings.zip_Mappings"这个标题和描述指向了一个关于SQL Server数据类型映射的主题,这通常涉及到不同系统或应用程序间数据类型的对应关系。在处理数据迁移、接口开发或集成时,理解这些映射...
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
When you change the mappings, you must calculate the size of the variables to be read from the PLC in order to use the correct Read Length parameter. The read length parameter is in transport size ...
This is a survey paper on balanced binary mappings defined on graphs. It contains proofs of several basic results.
ODBC Data Type Mappings.pdf 文件很可能包含了关于这些数据类型的更详细信息,包括它们在不同数据库系统中的具体映射,以及如何在实际开发中进行操作。了解这些映射对于编写跨平台的数据库应用程序至关重要,因为它...
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
EPIMap was able to achieve the theoretical best performance for 9 out of 14 benchmarks, while EMS could not achieve the theoreti- cal best performance for any of the benchmarks. EPIMap achieves ...
web.xml 最全 MIME Type Mappings 大概有 一千多个
IEEE Standard for Radio over Ethernet Encapsulations and Mappings(IEEE 1914.3标准)详细规定了如何利用RoE(Radio over Ethernet)技术封装和映射无线电协议数据,以便通过以太网帧传输。其主要涉及的知识点...
标签:airavata-rest-mappings-0.11.jar,airavata,rest,mappings,0.11,jar包下载,依赖包
标签:airavata-rest-mappings-0.10.jar,airavata,rest,mappings,0.10,jar包下载,依赖包