简体   繁体   English

休眠:在运行时生成动态POJO类和映射文件

[英]Hibernate: Generate dynamic POJO classes & Mapping files at RUNTIME

I am looking for a way to generate hibernate classes with XML mapping files at runtime. 我正在寻找一种在运行时使用XML映射文件生成休眠类的方法。
Using hibernate can save much more time than dealing with database myself using JDBC for example. 例如,与使用JDBC处理数据库本身相比,使用休眠可以节省更多时间。

Suppose I generated the POJO .java class, .class (ByteCode) with javassist library and it's .hbm.xml mapping file with the right syntax, will hibernate recognize it automatically without any additional configurations, or this process must be done at startup and requires application restarting? 假设我使用javassist库生成了POJO .java类,.class(ByteCode),并且它是具有正确语法的.hbm.xml映射文件,它将在没有任何其他配置的情况下自动休眠识别它,否则此过程必须在启动时完成并且需要应用程序重新启动?
If so What are those extra steps that are done on startup and can I do it at runtime? 如果是这样,那么在启动时需要执行哪些额外的步骤,我可以在运行时执行吗?

I searched a lot and read about Hibernate Dynamic Models but what if I need to connect and deal with some tables of the database before classes generation phase? 我进行了很多搜索并了解了Hibernate Dynamic Models,但是如果我需要在类生成阶段之前连接并处理数据库的某些表,该怎么办?

I read also about Ant Task and Spring Roo but still confused where to go.. 我也阅读了有关Ant TaskSpring Roo的文章,但仍然困惑该去哪里。

Has anyone handled such this thing before? 有人曾经处理过这样的事情吗?

Your advice please, Thanks in advance. 请给您意见,谢谢。

I like what you are trying to do, so I will contribute when you said: 我喜欢您要尝试做的事情,因此当您说:

Will hibernate recognize it automatically without any additional configurations, or this process must be done at startup and requires application restarting? Hibernate是否会在没有任何其他配置的情况下自动识别它,或者此过程必须在启动时完成并且需要重新启动应用程序?

Hibernate will recognise it but with additional modifications to hibernate.cfg file, ie, you need to add mapping properties for each entity, and this requires application restarting. Hibernate可以识别它,但是需要对hibernate.cfg文件进行其他修改,即,您需要为每个实体添加映射属性,这requires重新启动应用程序。

To avoid restarting your server I can only imagin deploying the application at runtime on a second server- after generating the required resources, if the first start up could be in the background that would make things better. 为了避免重新启动服务器,我只能想象在生成所需资源之后,如果在第一次启动时在后台运行,则会在运行时在第二台服务器上部署应用程序,这会使情况变得更好。

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

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