Hey, I'm working on a problem where users need to be able to dynamically add new fields/properties (columns) to persistent entities. I've been researching this for awhile now, and seem there were various solutions. The one I'm using now (prototyping) involves directly using the Hibernate API, i.e.
Code:
PersistentClass clazz = config.getClassMapping("some.class.Here");
Column col = new Column();
col.setName("Test");
col.setSqlType("varchar (255)");
I was thinking this would be a way for me to add the columns and properties at runtime (or when the session factory is created.) A few things I have yet to find answers on:
1. How do you set a property on a class you generate at runtime with Hibernate? I'm guessing it involves reflection, but not sure how.
2. Is there a file that defines the SqlType's that are valid to use with Hibernate?
3. Should I be setting the column on the Table? Or should I be creating a Property instead?
The other issue with this problem (I believe) will be updating the database schema when the user adds a new field. I think I can make this work with LiquiBase, but haven't implemented anything yet.
If anyone has any ideas or suggestions on this, I would be grateful. Thanks everyone