简体   繁体   中英

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.
Using hibernate can save much more time than dealing with database myself using JDBC for example.

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?
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?

I read also about Ant Task and Spring Roo but still confused where to go..

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 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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