org.hibernate.InvalidMappingException:无法解析资源中的映射文档 - > parseSessionFactory

时间:2017-10-11 00:55:31

标签: java hibernate

最近我将weblogic服务器从11g升级到12.2.1.3并重新部署Web应用程序。运行应用程序时,它会抛出异常。这会是错误的。我试图在网上谷歌,但没有运气,因为它正在创建会话问题。我认为在我根据谷歌搜索(例如https://stackoverflow.com/questions/12010056/org-hibernate-invalidmappingexceptioncould-not-parse-mapping-document-from-reso)尝试但是仍然存在相同问题时,在hiberate配置或映射xml文件中没有问题。

%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/xxxx/hibernate/SSmsPromotion.hbm.xml
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:588)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1606)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1574)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1553)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1527)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1447)
    at com.xxxx.hibernate.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)
    at com.xxxx.hibernate.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)
    at com.xxxx.onlineapplications.manager.SBranchManager.getSBranchCatList(SBranchManager.java:19)

public class SBranchManager{
    ...........
    public ArrayList getSBranchCatList(String langId, String appType) throws Exception{
        ArrayList branchCatList = new ArrayList();
        Session session = HibernateSessionFactory.getSession();  <--- Line 19
    ................

    }
}
public class HibernateSessionFactory {

    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;

    public static Session getSession() throws HibernateException {
        Session session = (Session) threadLocal.get();

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

        return session;
    }


    public static void rebuildSessionFactory() {
        try {
            configuration.configure(configFile);  <--- Line 69
            sessionFactory = configuration.buildSessionFactory(); 
        } catch (Exception e) {
            System.err
                    .println("%%%% Error Creating SessionFactory %%%%");
            e.printStackTrace();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

通过删除weblogic.xml中的以下行来解决此问题

<!--    <container-descriptor>
        <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor> -->