Is it possible to create hibernate Entity class(with annotations) during runtime? It should be related with the table that is also added in runtime. It is important that the Entity should be visible by the Hibernate. Is it possible in general, could you please give me any advices on the problem? I understand, that reflection is the keyword, but looking for some more words. Regards.
@Entity. The JPA specification requires the @Entity annotation. It identifies a class as an entity class. You can use the name attribute of the @Entity annotation to define the name of the entity.
The entity class must be annotated with the Entity annotation or denoted in the XML descriptor as an entity. So, if you use annotations for mappings, @Entity is mandated by the specification and Hibernate has to adhere to it.
The @Id annotation is inherited from javax.persistence.Id, indicating the member field below is the primary key of the current entity. Hence your Hibernate and spring framework as well as you can do some reflect works based on this annotation.
@Table annotation specifies the table name where data of this entity is to be persisted. If you don't use @Table annotation, hibernate will use the class name as the table name by default. @Id annotation marks the identifier for this entity.
In This scenario, you might want to create the Hibernate Session Factory programatic on the run time , passing in the new mapping that you have created , have a look at http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html#configuration-programmatic for details .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With