views:

489

answers:

3

Actually I am looking for something like this:

u alter the table in db (say u increase one column); it should be reflected in the front end wihtout hardcoding the mapping file...

thanks for help..

+2  A: 

hibernate is a ORM. So there is a object model in between the front end and the database. How should this object model represent the dynamic changes? Columns usually map to properties. If you add one in the database, you still miss the property in the class model.

If you would solve the problem in the object model using dictionaries, there is the option of directly map the dictionary as map, but then the data is not in columns, but in rows.

Or you map the dictionary as dynamic component, which will map to columns. This is probably what you are looking for.

What I'm trying to say: you should solve the problem in the object model first. Then you could ask how this can be mapped. If you don't have an object model, you don't need hibernate at all.

Stefan Steinegger
A: 

When Hibernate starts up it maps all the columns in the domain objects to columns in the tables and these are maintained by the SessionFactory. What you want to do is map "on the fly" which is not supported and you would have to create your own hybrid JPA/Hibernate install for this. Like @Stephan suggested I would start with the object model so make changes (add properties) to your domain objects and then propagate it to your db.

This would mean that all your current queries will now have to account for these new properties dynamically -- if all you have are from DomainObject queries then that's not an issue.

My point being that undertaking what you want creates immediate and non-orthogonal issues that just might not be worth it in my opinion. Consider some other strategy.

non sequitor
A: 

It is possible to generate hibernate configuration and domain classes based on database schema. Maybe this is what you are looking for? Of course, you would have to compile your app every time database schema changes.

Maybe you could consider also other mapping tools, like iBatis where you can define queries etc. in configuration.

Juha Syrjälä

related questions