Dynamically create tables and Java classes at run time
There are requirements in my application My table is not defined in advance For example, if a user creates a form by name and adds its properties, such as name, scroll number, subject, class, etc Then at runtime, there should be a table column name created by the name student, scroll no, class and its related classes and their hibernate mapping files Is there any way to do this?
Thank you in advance,
Rima Desai
Solution
This is possible, but it is not clear why you want to do so, so it is difficult to propose any specific solution
But usually, yes, you can dynamically generate database tables, hibernate classes and mappings based on some input The easiest way is to use some template engines I've used velocity in the past. This task is very good, but if you want to try them, there are others
Edit:
After OP clarification, it is better to use XML to store user - defined data The above solution is good, but it needs to recompile whether the application has changed the form If you don't want to stop and recompile after each user edit, XML is a better answer
Give you some first mover advantages:
@Entity public class UserDefinedFormData { @Id private long id; @ManyToOne private FormMetadata formMetadata; @Lob private String xmlUserData; }
Given the definition of a form, saving and loading data saved as XML is trivial
If you want more explanation, please add a comment