10

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 2

4

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 .

Sign up to request clarification or add additional context in comments.

3 Comments

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?
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
stackoverlow doesnt allow to write private messages. Could you pls post your code to any pastie service? Also ive written a private msg to your facebook:)
3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.