是否必须在使用注解和 hibernate 配置文件之间做出严格的选择,还是可以在同一项目中同时使用这两种方式?
我们有一个使用 Hibernate 3.2.5 和配置了 .hbm.xml
文件的 POJO 完成的大型项目。该项目使用 Hibernate SessionManager
工厂而不是基于 JTA 的 EntityManager
工厂。
以这种方式配置的 POJO 有一百多个,原始开发团队不愿意切换到注释。
与此同时,我们需要使用更多 POJO 扩展项目,我们愿意使用 Hibernate 注释配置这些 POJO,并且希望继续使用 Hibernate - 如果可能的话 - 而不是切换到 JPA。
是否可以同时对某些 POJO 使用 .hbm.xml
配置文件和对其他 POJO 使用注释?
最佳答案
是的,你可以。 Documentation说
Note that you can mix the legacy hbm.xml use and the annotation approach. The resource element can be either an hbm file or an EJB3 XML deployment descriptor.
虽然有几个检查点:
You can however not declare a class several times (whether annotated or through hbm.xml). You cannot mix configuration strategies (hbm vs annotations) in an entity hierarchy either.
您可以找到更多信息here .
关于java - 是否可以在 Hibernate 的同一个项目中同时使用注释和 hbm.xml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8311622/