zoukankan      html  css  js  c++  java
  • hibernate提示Unknown entity: :xxx

    错误提示:##

    org.hibernate.MappingException: Unknown entity: org.dao.po.Role
    	at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096)
    	at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1443)
    	at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:116)
    	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
    	at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
    	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
    	at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
    	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
    	at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
    	at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
    	at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
    	at org.dao.HibernateTest.main(HibernateTest.java:18)
    

    可能原因

    1. 引入的entity包有错误,应该引入: import javax.persistence.Entity;
    2. 没有在hibernate.cfg.xml中指定注解类<mapping class="org.dao.po.Role" />

    备注:

    如果使用配置文件配置pojo,那么在hibernate.cfg.xml文件中应该是引入文件<mapping resource="org/dao/po/Role.hbm.xml"></mapping>
    如果是使用注解,参考上面第二条

  • 相关阅读:
    洛谷P4547 [THUWC2017]随机二分图
    洛谷P4590 [TJOI2018]游园会
    洛谷P4099 [HEOI2013]SAO
    #4719. 内凸包
    #1612. 天平(scales)
    #3164. 「CEOI2019」立方填词
    #4728. 问题求解
    #2754. Count(count)
    sa模板
    bzoj 2553: [BeiJing2011]禁忌
  • 原文地址:https://www.cnblogs.com/donfaquir/p/9403776.html
Copyright © 2011-2022 走看看