• 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>
    如果是使用注解,参考上面第二条

  • 相关阅读:
    ios初级必看视频
    Md5加密
    Jmail发送邮件
    NPOI Helper文档
    jquery 序列化
    mvc DropDownList默认选项
    获取HTML
    EntityFramework Reverse POCO Generator工具
    全选反选
    mvc导出EXCEL
  • 原文地址:https://www.cnblogs.com/donfaquir/p/9403776.html
Copyright © 2020-2023  润新知