加油菜鸟 2009-10-21 14:52
浏览 232

hibernate的一个问题

配置文件如下:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


sa

jdbc:microsoft:sqlserver://10.28.9.10:1433;databasename=OA


org.hibernate.dialect.SQLServerDialect

SQL Server
sa

com.microsoft.jdbc.sqlserver.SQLServerDriver

<property name="show_sql">true</property>

<!-- 在这来添加新的映射文件 -->
<mapping resource="org/dpca/entity/Role.hbm.xml" />

出错提示为:
14:46:13,562 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(31) The element type "mapping" must be terminated by the matching end-tag "".
%%%% Error Creating SessionFactory %%%%
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml

新学hibernate,菜鸟一个,请各位帮我看看!
[b]问题补充:[/b]
我想可能其他的地方有问题,补充一下
package org.dpca.common.core;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;

/**

  • 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 HibernateSessionFactory {

    /**

    • Location of hibernate.cfg.xml file.
    • Location should be on the classpath as Hibernate uses
    • #resourceAsStream style lookup for its configuration file.
    • The default classpath location of the hibernate config file is
    • in the default package. Use #setConfigFile() to update
    • the location of the configuration file for the current session.
      */ private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml"; private static final ThreadLocal threadLocal = new ThreadLocal(); private static Configuration configuration = new Configuration(); private static org.hibernate.SessionFactory sessionFactory; private static String configFile = CONFIG_FILE_LOCATION;

    static {
    try {
    configuration.configure(configFile);
    sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
    System.err
    .println("%%%% Error Creating SessionFactory %%%%");
    e.printStackTrace();
    }
    }
    private HibernateSessionFactory() {
    }

    /**

    • Returns the ThreadLocal Session instance. Lazy initialize
    • the SessionFactory if needed. *
    • @return Session
    • @throws HibernateException
      */
      public static Session getSession() throws HibernateException {
      Session session = (Session) threadLocal.get();

      if (session == null || !session.isOpen()) {
      if (sessionFactory == null) {
      rebuildSessionFactory();
      }
      session = (sessionFactory != null) ? sessionFactory.openSession()
      : null;
      threadLocal.set(session);
      }

      return session;
      }

    /**

    • Rebuild hibernate session factory * */ public static void rebuildSessionFactory() { try { configuration.configure(configFile); sessionFactory = configuration.buildSessionFactory(); } catch (Exception e) { System.err .println("%%%% Error Creating SessionFactory %%%%"); e.printStackTrace(); } }

    /**

    • 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();
      }
      }

    /**

    • return session factory * */ public static org.hibernate.SessionFactory getSessionFactory() { return sessionFactory; }

    /**

    • return session factory *
    • session factory will be rebuilded in the next call */ public static void setConfigFile(String configFile) { HibernateSessionFactory.configFile = configFile; sessionFactory = null; }

    /**

    • return hibernate configuration * */ public static Configuration getConfiguration() { return configuration; }

}
[b]问题补充:[/b]
再补充一下
15:20:11,843 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(31) The element type "mapping" must be terminated by the matching end-tag "".
%%%% Error Creating SessionFactory %%%%
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at org.dpca.common.core.HibernateSessionFactory.(HibernateSessionFactory.java:30)
at org.dpca.common.core.BaseHibernateDao.getSession(BaseHibernateDao.java:49)
at org.dpca.common.core.BaseHibernateDao.(BaseHibernateDao.java:25)
at org.dpca.dao.RoleDao.(RoleDao.java:7)
at org.dpca.biz.RoleService.createRole(RoleService.java:20)
at test.Test.main(Test.java:20)
Caused by: org.dom4j.DocumentException: Error on line 31 of document : The element type "mapping" must be terminated by the matching end-tag "". Nested exception: The element type "mapping" must be terminated by the matching end-tag "".
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)
... 7 more
%%%% Error Creating SessionFactory %%%%
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at org.dpca.common.core.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)
at org.dpca.common.core.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)
at org.dpca.common.core.BaseHibernateDao.getSession(BaseHibernateDao.java:49)
at org.dpca.common.core.BaseHibernateDao.(BaseHibernateDao.java:25)
at org.dpca.dao.RoleDao.(RoleDao.java:7)
at org.dpca.biz.RoleService.createRole(RoleService.java:20)
at test.Test.main(Test.java:20)
Caused by: org.dom4j.DocumentException: Error on line 31 of document : The element type "mapping" must be terminated by the matching end-tag "". Nested exception: The element type "mapping" must be terminated by the matching end-tag "".
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)
... 8 more
15:20:11,859 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(31) The element type "mapping" must be terminated by the matching end-tag "".
null

  • 写回答

3条回答 默认 最新

  • 大雄学编程 2009-10-21 14:59
    关注


    是不是这个映射文件没有找到啊

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况