CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  框架、开源

散尽一千分,只为解决这个问题,在CSDN一个月没人解决得了的问题

楼主fmdsaco(老小不大)2006-08-18 11:13:02 在 Java / 框架、开源 提问

出错环境:tomcat5.028   +hibernate3.0  
  声明:开发环境ECLIPSE3.1,在ECLIPSE调试从来没出现这样的错误,在TOMCAT运行的时候才出现这样的错误。  
  出现的时间:TOMCAT刚启动、第一次调用HIBERNATE的时候,如果重试几次后,运行正常,,  
  个人认为:  
  第一是HIBERNATE.CFG.XML语法上有错(检查了不下百次没发现错,本人不太懂XML),  
  第二:就是在TOMCAT读HIBERNATE时读不到这个文件,我试过读其它文件的时候也正常的  
  出错内容(错误信息由LOG4J输出):  
  2006-08-18   11:05:13,782   INFO     (Configuration.java:1110)   -   configuring   from   resource:   /com/power/data/hibernate.cfg.xml  
  2006-08-18   11:05:13,782   INFO     (Configuration.java:1081)   -   Configuration   resource:   /com/power/data/hibernate.cfg.xml  
  2006-08-18   11:05:13,782   INFO     (Configuration.java:1110)   -   configuring   from   resource:   /com/power/data/hibernate.cfg.xml  
  2006-08-18   11:05:13,797   INFO     (Configuration.java:1081)   -   Configuration   resource:   /com/power/data/hibernate.cfg.xml  
  2006-08-18   11:05:13,813   ERROR   (Configuration.java:1172)   -   problem   parsing   configuration/com/power/data/hibernate.cfg.xml  
  org.dom4j.DocumentException:   FWK005   parse   may   not   be   called   while   parsing.   Nested   exception:   FWK005   parse   may   not   be   called   while   parsing.  
  at   org.dom4j.io.SAXReader.read(SAXReader.java:484)  
  at   org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1168)  
  at   org.hibernate.cfg.Configuration.configure(Configuration.java:1112)  
  at   com.power.data.HibernateFactory.currentSession(HibernateFactory.java:59)  
  at   com.power.publics.GetSession.GetData(GetSession.java:130)  
  at   com.bat.logic.user.UserLogin.logincheck(UserLogin.java:37)  
  相关配置:  
  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="dialect">org.hibernate.dialect.SQLServerDialect</property>  
  <property   name="connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433;SelectMethod=cursor;DatabaseName=dei_net_ftjls</property>  
  <property   name="connection.username">sa</property>  
  <property   name="connection.password">powerdata</property>  
  <property   name="show_sql">false</property>  
  <property   name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>  
  </session-factory>  
   
  </hibernate-configuration>  
   
  运行时,把表对像(.hbm.xml)全部删掉一样出错,  
  问题点数:100、回复次数:29Top

1 楼fmdsaco(老小不大)回复于 2006-08-18 11:13:51 得分 0

其它表对配置如下:  
  <?xml   version="1.0"?>    
  <!DOCTYPE   hibernate-mapping   PUBLIC     "-//Hibernate/Hibernate   Mapping   DTD   3.0//EN"   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">      
  <hibernate-mapping   package="com.power.hibernate">    
  <class   name="FCode_tbl"   table="code_tbl">    
  <composite-id   name="codekey"   class="Code_key">  
  <key-property   name="ename"   type="java.lang.String"   length="50"/>  
  <key-property   name="datas"   type="java.lang.String"   length="20"/>  
  </composite-id>  
  <property   name="cname"   column="cname"   type="java.lang.String"   length="50"/>      
  <property   name="display"   column="display"   type="java.lang.String"   length="100"/>      
  </class>          
  </hibernate-mapping>    
  Top

2 楼fmdsaco(老小不大)回复于 2006-08-18 11:14:45 得分 0

其它贴子:  
  http://community.csdn.net/Expert/TopicView3.asp?id=4919209  
  http://community.csdn.net/Expert/TopicView3.asp?id=4952640Top

3 楼SDMRauquin(冷月无心)回复于 2006-08-18 11:18:35 得分 0

class里面是否生成了?Top

4 楼fmdsaco(老小不大)回复于 2006-08-18 11:19:12 得分 0

CLASS生成啦  
  Top

5 楼SDMRauquin(冷月无心)回复于 2006-08-18 11:21:02 得分 0

说实话   这些配置文件我的都是Myecliose生成的,几乎不用手动,所以一般我的不会出现写法错误Top

6 楼fmdsaco(老小不大)回复于 2006-08-18 11:21:09 得分 0

HibernateFactory.java如下  
     
   
  import   java.io.File;  
   
  import   org.hibernate.HibernateException;  
  import   org.hibernate.Session;  
  import   org.hibernate.cfg.Configuration;  
   
  import   com.power.publics.ChangType;  
   
  /**  
    *   Configures   and   provides   access   to   Hibernate   sessions,   tied   to   the   current  
    *   thread   of   execution.   Follows   the   Thread   Local   Session   pattern,   see  
    *   {@link   http://hibernate.org/42.html}.  
    */  
  public   class   HibernateFactory   {    
     
  /**  
    *   Location   of   hibernate.cfg.xml   file.   NOTICE:   Location   should   be   on   the  
    *   classpath   as   Hibernate   uses   #resourceAsStream   style   lookup   for   its  
    *   configuration   file.   That   is   place   the   config   file   in   a   Java   package   -   the  
    *   default   location   is   the   default   Java   package.<br>  
    *   <br>  
    *   Examples:   <br>  
    *   <code>CONFIG_FILE_LOCATION   =   "/hibernate.conf.xml".    
    *   CONFIG_FILE_LOCATION   =   "/com/foo/bar/myhiberstuff.conf.xml".</code>  
    */  
   
  private   static   String   CONFIG_FILE_LOCATION   =   "/com/power/data/hibernate.cfg.xml";  
   
  /**   Holds   a   single   instance   of   Session   */  
  private   static   final   ThreadLocal   threadLocal   =   new   ThreadLocal();  
   
  /**   The   single   instance   of   hibernate   configuration   */  
  private   static   final   Configuration   cfg   =   new   Configuration();  
   
   
  /**   The   single   instance   of   hibernate   SessionFactory   */  
  private   static   org.hibernate.SessionFactory   sessionFactory;  
   
  /**  
    *   Returns   the   ThreadLocal   Session   instance.   Lazy   initialize   the  
    *   <code>SessionFactory</code>   if   needed.  
    *    
    *   @return   Session  
    *   @throws   HibernateException  
    */  
  public   static   Session   currentSession()   throws   HibernateException   {  
  Session   session   =   (Session)   threadLocal.get();  
   
                    //////cfg.configure("G:\\FMDBAT\\ebcm_net\\WEB-INF\\src\\com\\power\\hibernate\\data\\hibernate.cfg.xml");  
                       
  if   (session   ==   null)   {  
  if   (sessionFactory   ==   null)   {  
  try   {  
      ////cfg.configure("G:\\FMDBAT\\ebcm_net\\WEB-INF\\src\\com\\power\\hibernate\\data\\hibernate.cfg.xml");  
                       
    cfg.configure(CONFIG_FILE_LOCATION);  
    HibernateFactory.getHbmXml("");  
  sessionFactory   =   cfg.buildSessionFactory();  
  System.out.println("建立成功");  
  }   catch   (Exception   e)   {  
  System.err  
  .println("%%%%   Error   Creating   SessionFactory   %%%%");  
  e.printStackTrace();  
  }  
  }  
  session   =   sessionFactory.openSession();  
  threadLocal.set(session);  
  }  
   
  return   session;  
  }  
   
  /**      
    *   Close   the   single   hibernate   session   instance.  
    *    
    *   @throws   HibernateException  
    */  
  public   static   void   closeSession()   throws   HibernateException   {  
  Session   session   =   (Session)   threadLocal.get();  
  threadLocal.set(null);  
   
  if   (session   !=   null)   {  
  session.close();  
  }  
  }  
   
   
  public   static   void   getHbmXml(String   path)   {  
  path="G:\\FMDBAT\\ebcm_net\\WEB-INF\\src\\com\\power\\hibernate";  
  File   d   =   new   File(path);//   建立当前目录中文件的File对象  
  File   lists[]   =   d.listFiles();//   取得代表目录中所有文件的File对象数组  
    ChangType   type=new   ChangType();  
     
  int   ii=0,jj=0;  
    String   temp="",xml="";  
  for   (int   i   =   0;   i   <   lists.length;   i++)   {  
  if   (lists[i].isFile())   {  
  temp=lists[i].getName();  
  ii=temp.trim().length();      
   
  if(ii>10){  
  jj=ii-8;    
      temp=temp.substring(jj,ii);      
    if(temp.equals(".hbm.xml")){  
    xml="com/power/hibernate/"+lists[i].getName().trim();  
    System.out.println(xml+"     xml");  
    cfg.addResource(xml);  
   
  ////   cfg.addResource("com/power/hibernate/FCode_tbl.hbm.xml");  
    ////   System.out.println("加载   com/power/hibernate/"+lists[i].getName()+"   ");  
    }  
  }  
   
  }  
  }  
     
  }  
   
   
     
  /**  
    *   Default   constructor.  
    */  
  private   HibernateFactory()   {  
  }  
   
  }  
  Top

7 楼SDMRauquin(冷月无心)回复于 2006-08-18 11:22:02 得分 0

在ECLIPSE调试从来没出现这样的错误,在TOMCAT运行的时候才出现这样的错误。  
   
  你再启动的时候,不是启动TOMCAT?Top

8 楼SDMRauquin(冷月无心)回复于 2006-08-18 11:24:22 得分 0

HibernateSessionFactory.java也是My生成的,不过没有这么多内容:  
   
  public   class   HibernateSessionFactory   {  
   
          /**    
            *   Location   of   hibernate.cfg.xml   file.  
            *   NOTICE:   Location   should   be   on   the   classpath   as   Hibernate   uses  
            *   #resourceAsStream   style   lookup   for   its   configuration   file.   That  
            *   is   place   the   config   file   in   a   Java   package   -   the   default   location  
            *   is   the   default   Java   package.<br><br>  
            *   Examples:   <br>  
            *   <code>CONFIG_FILE_LOCATION   =   "/hibernate.conf.xml".    
            *   CONFIG_FILE_LOCATION   =   "/com/foo/bar/myhiberstuff.conf.xml".</code>    
            */  
          private   static   String   CONFIG_FILE_LOCATION   =   "/hibernate.cfg.xml";  
   
          /**   Holds   a   single   instance   of   Session   */  
          private   static   final   ThreadLocal<Session>   threadLocal   =   new   ThreadLocal<Session>();  
   
          /**   The   single   instance   of   hibernate   configuration   */  
          private   static   final   Configuration   cfg   =   new   Configuration();  
   
          /**   The   single   instance   of   hibernate   SessionFactory   */  
          private   static   org.hibernate.SessionFactory   sessionFactory;  
   
          /**  
            *   Returns   the   ThreadLocal   Session   instance.     Lazy   initialize  
            *   the   <code>SessionFactory</code>   if   needed.  
            *  
            *     @return   Session  
            *     @throws   HibernateException  
            */  
          public   static   Session   currentSession()   throws   HibernateException   {  
                  Session   session   =   (Session)   threadLocal.get();  
   
                  if   (session   ==   null)   {  
                          if   (sessionFactory   ==   null)   {  
                                  try   {  
                                          cfg.configure(CONFIG_FILE_LOCATION);  
                                          sessionFactory   =   cfg.buildSessionFactory();  
                                  }  
                                  catch   (Exception   e)   {  
                                          System.err.println("%%%%   Error   Creating   SessionFactory   %%%%");  
                                          e.printStackTrace();  
                                  }  
                          }  
                          session   =   sessionFactory.openSession();  
                          threadLocal.set(session);  
                  }  
   
                  return   session;  
          }  
   
          /**  
            *     Close   the   single   hibernate   session   instance.  
            *  
            *     @throws   HibernateException  
            */  
          public   static   void   closeSession()   throws   HibernateException   {  
                  Session   session   =   (Session)   threadLocal.get();  
                  threadLocal.set(null);  
   
                  if   (session   !=   null)   {  
                          session.close();  
                  }  
          }  
   
          /**  
            *   Default   constructor.  
            */  
          private   HibernateSessionFactory()   {  
          }  
   
  }Top

9 楼sakas(feeling)回复于 2006-08-18 11:24:30 得分 1

帮你顶一下Top

10 楼fmdsaco(老小不大)回复于 2006-08-18 11:27:58 得分 0

SDMRauquin(冷月无心)    
  我可以在ECLIPSE调用调试HIBERNTE,不用启动TOMCAT可以读数,,  
   
  我的HibernateSessionFactory   也是MY自动生成的Top

11 楼fmdsaco(老小不大)回复于 2006-08-18 11:28:16 得分 0

是加上一些东西Top

12 楼SDMRauquin(冷月无心)回复于 2006-08-18 11:35:25 得分 0

你原来成功过hibernate吗?  
   
  hibernate.cfg.xml里面的配置对了没?  
  就是那些<mapping>的Top

13 楼SDMRauquin(冷月无心)回复于 2006-08-18 11:37:02 得分 80

你的hibernate.cfg.xml里面是没有配<mapping>?还是没有贴出来  
   
      <mapping   resource="org/caexpo/nanbo/model/TUser.hbm.xml"></mapping>  
          <mapping   resource="org/caexpo/nanbo/model/TBuyer.hbm.xml"></mapping>  
          <mapping   resource="org/caexpo/nanbo/model/TChildtrade.hbm.xml"></mapping>  
          <mapping   resource="org/caexpo/nanbo/model/TCorpscale.hbm.xml"></mapping>  
          <mapping   resource="org/caexpo/nanbo/model/TCountry.hbm.xml"></mapping>  
          <mapping   resource="org/caexpo/nanbo/model/TLanguage.hbm.xml"></mapping>  
          <mapping   resource="org/caexpo/nanbo/model/TSeller.hbm.xml"></mapping>Top

14 楼fmdsaco(老小不大)回复于 2006-08-18 11:37:18 得分 0

SDMRauquin(冷月无心)  
  现在是有时不成功,,就是开始的时候,,我把MAPPPING全去掉也一样的错误Top

15 楼fmdsaco(老小不大)回复于 2006-08-18 11:38:33 得分 0

我不要MAPPING来测试一样的错Top

16 楼SDMRauquin(冷月无心)回复于 2006-08-18 11:43:13 得分 0

你的是用Ec开发的吗?多大,是否方便发给我我帮你调试看看Top

17 楼fmdsaco(老小不大)回复于 2006-08-18 11:44:17 得分 0

是呀,,好的  
  Top

18 楼fmdsaco(老小不大)回复于 2006-08-18 11:45:46 得分 0

我的MSN   :fmdsaco@hotmail.comTop

19 楼will123()回复于 2006-08-18 14:09:32 得分 1

学习Top

20 楼xiaoyaowp(huanong)回复于 2006-08-18 14:25:26 得分 1

帮你顶了Top

21 楼donggua12345678()回复于 2006-08-18 14:32:19 得分 1

友情支持Top

22 楼alexwan(牧林:才多身子弱)回复于 2006-08-18 14:33:21 得分 1

似乎很高深的样子……Top

23 楼aotsuki(Colin Liu)回复于 2006-08-18 16:19:27 得分 1

哈哈,不懂Top

24 楼myminimouse(坚决不用baidu)回复于 2006-08-18 16:49:35 得分 1

jfTop

25 楼zmzbs123(小阵阵)回复于 2006-08-18 16:53:37 得分 1

明明只有100分!lz不厚道!Top

26 楼boxigroup()回复于 2006-08-19 14:15:56 得分 0

欢迎光监点石成金网   http://www.boxigroup.com   网站提供web开发(j2ee   .net   asp   php   javascript、c#等)   c/s开发(delphi、vb、vc、pb、cb等)   数据库开发(oracle、sqlserver、db2、access、mysql、Postgresql、informix)等学习资料,希望能为你解决燃眉之急   ,请把本网站加入收藏夹,以备不时查询之需   bs+cs讨论群(9638134)Top

27 楼YuLimin(阿敏总司令:简单就是美—钻石闪闪您快结贴!)回复于 2006-08-21 00:21:50 得分 10

使用XMLSpy之类的编辑工具格式化并校验一下XML文件,同时检查XML文件本身的编码问题,可能是因为保存的编码问题导致读取XML文件时发生错误的,用UltraEdit打开看看里面二进制的内容是否有问题。Top

28 楼fxy1(初学者)回复于 2006-09-01 17:21:16 得分 1

我用Hibernate也有时出现问题,让人感觉是配置文件出了错。但有时在Main()下运行的,执行很好,但在Web环境下同样的语句也出错,让人费解。总觉的Hibernate的出错提示做的真不好,有时是好的,有时报错。还弄不明白是什么原因。Top

29 楼seesea10523()回复于 2006-09-01 17:40:25 得分 1

学习Top

相关问题

关键词

得分解答快速导航

  • 帖主:fmdsaco
  • sakas
  • SDMRauquin
  • will123
  • xiaoyaowp
  • donggua12345678
  • alexwan
  • aotsuki
  • myminimouse
  • zmzbs123
  • YuLimin
  • fxy1
  • seesea10523

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo