简体   繁体   English

多线程休眠中的未知实体

[英]Unknown Entity in multithreading hibernate

We are converting a large database from one DBMS to another. 我们正在将一个大型数据库从一个DBMS转换为另一个。 We are mostly using JDBC for this but there are some Hibernate calls mixed in. So far, a small portion of the database is taking seven hours to migrate. 为此,我们主要使用JDBC,但其中混入了一些Hibernate调用。到目前为止,一小部分数据库迁移需要七个小时。 To mitigate this, we decided we could migrate different parts of the database simultaneously. 为了减轻这种情况,我们决定可以同时迁移数据库的不同部分。 We rewrote the migration routine to use threads. 我们重写了迁移例程以使用线程。 After wading through Java heap space issues and making sure we had separate JDBC and Hibernate sessions in each thread, we found ourselves with one last problem: We are getting Unknown entity: exceptions everywhere. 解决了Java堆空间问题并确保每个线程中都有单独的JDBC和Hibernate会话后,我们发现自己遇到了最后一个问题:我们正在获得Unknown实体:无处不在的异常。 We are creating a SchemaExport and executing it before any migration thread starts. 我们正在创建一个SchemaExport并在任何迁移线程开始之前执行它。 What are we missing? 我们缺少什么?

Apparently, Unknown entity is an exception which happens when hibernate doesn't know about the class which is referenced in the exception. 显然,未知实体是一个异常,当休眠不知道该异常中引用的类时会发生这种情况。 eg, for the Myclass class: 例如,对于Myclass类:

Exception in thread "main" org.hibernate.MappingException: Unknown entity: data.Myclass

You need to have a <classname>.hbm.xml file, which corresponds to a hibernate mapping, in order for each class that must be known by hibernate, and also have these files referenced as resources in the main configuration file of hibernate. 您需要具有一个与休眠映射相对应的<classname>.hbm.xml文件,以便每个必须由hibernate知道的类,还必须在hibernate的主配置文件中将这些文件作为资源引用。 in hibernate.cfg.xml , this is the line to let hibernate know about the class Myclass : hibernate.cfg.xmlMyclass hibernate了解类Myclass

<mapping resource="Myclass.hbm.xml" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM