• Hibernate 4 升级到 5 后显示未知实体错误


    提示的错误信息如下:

    org.hibernate.MappingException: Unknown entity: com.ossez.reoc.common.crm.DoNotCall
      at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(MetamodelImpl.java:670)
      at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1721)
      at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:118)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
      at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
      at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
      at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:713)
      at org.hibernate.internal.SessionImpl.save(SessionImpl.java:705)
      at org.hibernate.internal.SessionImpl.save(SessionImpl.java:700)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:350)
      at com.sun.proxy.$Proxy51.save(Unknown Source)
      at com.ossez.reoc.common.Factory.save(Factory.java:159)
      at com.ossez.reoc.common.crm.factories.DoNotCallFactory.save(DoNotCallFactory.java:27)
      at com.ossez.reoc.common.tests.DoNotCallTest.testCreate(DoNotCallTest.java:23)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at junit.framework.TestCase.runTest(TestCase.java:176)
      at junit.framework.TestCase.runBare(TestCase.java:141)
      at junit.framework.TestResult$1.protect(TestResult.java:122)
      at junit.framework.TestResult.runProtected(TestResult.java:142)
      at junit.framework.TestResult.run(TestResult.java:125)
      at junit.framework.TestCase.run(TestCase.java:129)
      at junit.framework.TestSuite.runTest(TestSuite.java:252)
      at junit.framework.TestSuite.run(TestSuite.java:247)
      at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    

     

    这个错误很有可能是你的 SessionFactory 在初始化的时候出现了错误。

    导致了 Hibernate 不能找到正确的实体配置。

    请参考: Hibernate 4 升级到 Hibernate 5 的时候 SessionFactory 不能使用 中的内容。

  • 相关阅读:
    ESLint 配置说明
    ThinkPhp 更改 BIT 类型的问题
    sql server management studio 查询的临时文件路径
    Excel分组快速自动填充编号
    ThinikPhp 将数据库模型的增、删、改操作写入日志
    Window 任务栏清除历史记录
    vscode 中使用php-cs-fixer和PHP Formatter 插件规范化PHP代码
    ThinkPhp 使用PhpExcel导出导入多语言文件
    [UE4]抛物线指示器
    [UE4]瞬移
  • 原文地址:https://www.cnblogs.com/huyuchengus/p/11676290.html
Copyright © 2020-2023  润新知