是否有可能在Hibernate的同一个项目中同时使用注释和hbm.xml文件? [英] Is it possible to use both annotations and hbm.xml files in the same project in Hibernate?

查看:100
本文介绍了是否有可能在Hibernate的同一个项目中同时使用注释和hbm.xml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否必须在使用注释和hibernate配置文件之间做出严格的选择,还是可以在同一个项目中同时使用两种方式?



我们有一个用Hibernate 3.2.5和POJO配置的大型项目,它们使用 .hbm.xml 文件进行配置。该项目使用Hibernate SessionManager 工厂,而不是基于JTA的 EntityManager 工厂。



这样配置了100多个POJO,原始开发人员团队不愿意切换到注释。同时,我们需要用更多的POJO来扩展项目,我们愿意使用Hibernate注释来配置它们,并且希望保留Hibernate,如果可能的话,并且不要切换到JPA。



是否可以将 .hbm.xml 配置文件组合用于某些POJO和其他人的注释同样的时间?

解决方案

Manu已经给出了答案,但是如果您要切换到注释并且想要将这些hbm .xml注释。请继续。您可以使用将从现有表中生成注释的pojo类的工具。即使使用这些工具,您不必更改其他代码就像以前一样生成pojos。即不要更改属性名称。我曾在同一个项目上工作过,我使用过Ant脚本。


Does one necessarily have to make a strict choice between using annotations and hibernate configuration files, or is it possible to use both ways at the same time in the same project?

We have a large project done with Hibernate 3.2.5 and POJOs configured with .hbm.xml files. The project uses Hibernate SessionManager Factory and not JTA-based EntityManager factory.

There are over a hundred POJOs configured that way and the original developer team is reluctant to switch to annotations.

Meanwhile we need to extend the project with more POJOs which we are willing to configure with Hibernate annotations and want to stay with Hibernate - if possible - and not switch to JPA.

Is it possible to use a combination of .hbm.xml config files for some POJOs and annotations for others at the same time?

解决方案

Manu has given the answer but if you are going to switch to annotations and you want to convert those hbm.xml to annotations. Please go on. You can use the tools that will generate the pojo classes with annotations from existing tables. Even using those tools, You dont have to change the other code just generate the pojos like before. i.e. dont change property names. I have worked on same kinda project and I used Ant script for that.

这篇关于是否有可能在Hibernate的同一个项目中同时使用注释和hbm.xml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆