Is it possible to create hibernate Entity class(with annotations) during runtime? It should be related with the table that is also added in runtime. It is important that the Entity should be visible by the Hibernate. Is it possible in general, could you please give me any advices on the problem? I understand, that reflection is the keyword, but looking for some more words. Regards.
2 Answers
In This scenario, you might want to create the Hibernate Session Factory programatic on the run time , passing in the new mapping that you have created , have a look at http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html#configuration-programmatic for details .
3 Comments
gis_wild
Thank you for the answer. On your link the information is about java pojo + *.hbm.xml file. Will it be work with java annotated class withoud *.hbm.xml?
Akash Yadav
are you using it as standalone or with spring ?, if you are using spring and its configured as annotation driven it work , am not sure about the other as i never used, do write to me , in case you need a working example of the same
gis_wild
stackoverlow doesn
t allow to write private messages. Could you pls post your code to any pastie service? Also ive written a private msg to your facebook:)You don't need to create a POJO entity class and instance at run time. What you need is the Hibernate dynamic models. Please refer to http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/#persistent-classes-dynamicmodels.