加油菜鸟 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
    关注


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

    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名