tags:

views:

52

answers:

1

i AM A HIBERNATE BEGINNER ,Since i need to create dynamic tables with dynamic fields in them i chose to use hibernate . As far as my understanding , creating tables requires a class with the fields defined in the class . How do i generate the classes dynamically based on the table with the required fields ?

A: 

I'm not sure I understood the question (the title is about creation of tables, the last part is about creation of classes, pretty confusing). Maybe you should clarify your question and the problem you need to solve.

If you want to create Java classes from the physical model before the runtime, have a look at Hibernate Tools (and especially hbm2java).

If you want to create classes at runtime, I'm afraid this won't be possible with Hibernate. Actually, if your question is about runtime, Hibernate might not be the right tool.


I will be designing the table structure in html form and i want to convert into relevant database model. I should be able to insert and retrieve values from them.

There is jdbcpersistence which generates the mapping classes at runtime. This sounds like it could be what you are looking for. Note that I don't have ANY experience with this tool.

Pascal Thivent
you are pretty much close to my question. Thanks for your information. But what i want in simple way you can say, I will be designing the table structure in html form and i want to convert into relevant database model. I should be able to insert and retrieve values from them.
@user369316: Ok, so if I'm following you, this means creating tables during runtime. In that case, Hibernate is not the right tool (mapped classes are loaded by Hibernate at startup, I don't think you can add more of them later, assuming you were able to generate them and compile them dynamically).
Pascal Thivent
can you give me any idea of doing so? else you can suggest me any way of doing in JAVA?
I guess you still can use hibernate, only without mapped classes or HQL i.e. running all queries in pure sql :) Maybe not the greatest use for hibernate but probably there are still some benefits (caching, transaction management?)
serg
@serg555 Indeed (although I'm not sure you'll benefit from caching).
Pascal Thivent