views:

120

answers:

2

Hi.

I want to implement a class which its fields could change (add new fields) through time. The problem is that I want to give my client this ability to do this himself by just completing a form of what field and which type he wants and then the change will be done automatically! Does anyone have any idea how can I implement this class and make this change in my database using hibernate annotation?

Thanks in advance.

A: 

You should use a map of name-value pairs. Maps are supported by Hibernate per se, and their contents are dynamic.

Péter Török
Thanks. Sorry I'm new with hibernate. from my understanding hibernate creates a new table for the hash map. if values of my hash map be an object from another class, does hql supports a query which needs to select some values from that object? In another words does hql support nested select queries in this case?
Zim
@Zahra, there is usually no table needed for the map itself, only for the contained objects (if these are entities themselves). AFAIK HQL in general supports nested selects. But the map contents are loaded by Hibernate automatically upon access, so you can also do a simple lookup within the map instead of HQL.
Péter Török
Thank you very much. Well actually I need HQL query because I have a search that needs some fields of the object that I put in map!
Zim
A: 

You definitely can't make that change using Hibernate Annotations, since annotations can only be attached to a class at compile time. However if you want to change the structure of your class at runtime (add fields, methods, etc.) you will have to recompile the class and recreate the database mapping Hibernate uses to access your database.

perdian