zoukankan      html  css  js  c++  java
  • org.hibernate.MappingException:Unknown entity

    转自:https://www.cnblogs.com/jinjiyese153/p/6902785.html

    1.问题描述:

      使用*.hbm.xml文件进行hibernate测试时,运行报错如下:

    2.解决方案

      可能一:将*.hbm.xml中的class标签中的name写为类所在路径。

        错误时为:

    1
    <class name="Student" table="STUDENTS">

        修改后为:

    1
    <class name="org.hibernate.model.Student" table="STUDENTS">

       可能二:可能是获取sessionFactory方式有问题

        hibernate4.35之前sessionFactory获取方式

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    // 创建配置对象
    Configuration config = new Configuration().configure();
    // 创建服务注册对象(hibernate4.35之后该方法就不能再获取到实体信息了)
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySettings(config.getProperties()).build();
    // 创建会话工厂对象
    sessionFactory = config.buildSessionFactory(serviceRegistry);
    // 创建会话
    session = sessionFactory.openSession();
    // 开启事务
    transaction = session.beginTransaction();

        hibernate4.35之后sessionFactory获取方式

    1
    2
    3
    4
    5
    6
    // 创建会话工厂对象
    sessionFactory = new Configuration().configure().buildSessionFactory();
    // 创建会话
    session = sessionFactory.openSession();
    // 开启事务
    transaction = session.beginTransaction();

      

  • 相关阅读:
    hdu 5961 传递(暴力搜索)
    hdu 3577 Fast Arrangement(线段树区间修改,求区间最小值)
    hdu 5898 odd-even number(数位dp)
    Python-编码
    Golang-教程
    Python-待
    Python_每日习题_0006_斐波那契数列
    计算机网络
    Python_老男孩练习题1
    Python_内置函数2_44
  • 原文地址:https://www.cnblogs.com/sharpest/p/11113894.html
Copyright © 2011-2022 走看看