当前位置:编程学习 > JAVA >>

用Hibernate时出错.请高手帮忙解决一下.

用Hibernate 时 出现这个错误 
SessionFactory 创建不成功,是怎么回事?
是不是映射文件写错了.但是映射文件是 自动生成的,不应该有错吧.
请哪位大峡 帮的看一下:



%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:102)
at org.hibernate.cfg.Configuration.add(Configuration.java:474)
at org.hibernate.cfg.Configuration.add(Configuration.java:470)
at org.hibernate.cfg.Configuration.add(Configuration.java:642)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:725)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2088)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2060)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2040)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1993)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1908)
at net.book.dao.jdbc.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:29)
at net.book.dao.impl.MemberDaoImpl.listFriend(MemberDaoImpl.java:127)
at net.book.service.impl.MemberServiceImpl.listFriend(MemberServiceImpl.java:193)
at net.book.web.actions.MessageAction.listFriend(MessageAction.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at c
--------------------编程问答-------------------- 你使用的是集成spring吗? --------------------编程问答-------------------- 单独的hibernate,是不是有些jar没导入? --------------------编程问答-------------------- 需要的jar包都导入进去了,spring 算是没有用到.没用spring的容器去创建.一些类是我自己创建的. --------------------编程问答-------------------- 1、*.hbm.xml文件的路径不对。这分两个小点,一是本身这个文件的位置没有放对,二是hibernate.cfg.xml中配置的路径不对,这就取决于我们喜欢改那个地方了。

    2、*.xml的文件中存在语法错误。一般用工具生成的xml文件不会存在这类错误,但是对于像我这样的初学者,喜欢自己去手动配置,这就难免会遇到输入错误的情况。


百度到的,你看下是不是在这里面 --------------------编程问答-------------------- 你把你的application.xml的内容贴出来,里面有个bean是管理sessionFactory的,里面有个classpath:hibernate.cfg.xml,这个你有写吗 --------------------编程问答-------------------- 最好把 web.xml、hbm.cfg.xml等等xml文件内容粘贴出来看看

错误:“Unable to read XML”
at net.book.dao.jdbc.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:29)
    at net.book.dao.impl.MemberDaoImpl.listFriend(MemberDaoImpl.java:127)
    at net.book.service.impl.MemberServiceImpl.listFriend(MemberServiceImpl.java:193)
    at net.book.web.actions.MessageAction.listFriend(MessageAction.java:51)
--------------------编程问答-------------------- 检查一下你的 驱动类,应该是 class14.jar才对
--------------------编程问答-------------------- 从异常上来看是由你的xml配置文件引起的。 --------------------编程问答-------------------- 这是web.xml 里面的内容:
<display-name>books_family</display-name>
<!-- Set Charcter Encoding -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/config/applicationContextDao.xml,
/WEB-INF/classes/config/book_dao.xml,
/WEB-INF/classes/config/book_service.xml,
/WEB-INF/classes/config/book_servlet.xml
</param-value>
</context-param>



你把你的application.xml的内容贴出来,里面有个bean是管理sessionFactory的,里面有个classpath:hibernate.cfg.xml,这个你有写吗

用到的类,我是自己手动创建的.这个配置 可以不用吧?? --------------------编程问答-------------------- spring 自动帮你托管了,你自己建立不出来的,我前两天试过。 --------------------编程问答--------------------    /WEB-INF/classes/config/book_servlet.xml
这不是编译后的文件吗 大哥src里的才是源码啊。。 --------------------编程问答-------------------- 继承的hibernateDao的dao里,直接覆写spring 的hibernateDao的SessionFactory getSessionFactory() 方法就行了。
  --------------------编程问答-------------------- 我在Dao 层 测试了一下。能取到数据。 在service层也测试了一下。独自运行的话,都是可以取到数据的。但是一启动Tomcat 取数据的时候就会出问题!
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,