samedi 30 mai 2015

Create table programatically from entity annotation under JPA

Suppose the JPA provider is hibernate. Suppose it is not container managed, but application managed.

Given an entity class and correct annotation, is it possible to create table programatically, at runtime, and only for that class? By saying runtime, it means the entity class is not listed in the persistence.xml.

Theoretically, it is possible because we can manually read the annotations and generate SQL, and from the persistence unit we can read database connection url. My question is, is there anyway to do it without duplicating lots of work inside hibernate?

I found in other SO questions that Persistence.createSchema could be used, but I don't see where to specify the class.

Aucun commentaire:

Enregistrer un commentaire