1

Found an article in springsource which describes how to manipulate the schema name at runtime.

http://forum.springsource.org/showthread.php?18715-changing-hibernate-schemas-at-runtime

We're using pure jpa however where were using a LocalContainerEntityManagerFactory and don't have access to Session or Conofiguration instances.

Can anyone provide insight on how to access the metadata at runtime (via the entitymanager) to allow modifying the schema?

Thanks

skellish
  • 11
  • 1

2 Answers2

1

You can't using standard JPA (which is your requirement going by your question); it doesn't allow you to dynamically define metadata, only view (a limited amount of) specified metadata via its metamodel API. You'd have to delve into implementation specifics to get further, but then your portability goes down the toilet at that point, which isn't a good thing.

JDO, on the other hand, does allow you to dynamically define metadata (and hence schema) using standardised APIs.

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
1

Changing meta-data at runtime is JPA provider specific. JPA allows you to pass a Map of provider specific properties when creating an EntityManagerFactory or EntityManager. JPA also allows you to unwrap() an EntityManager to a provider specific implementation.

If you are using EclipseLink you can set the schema using the setTableQualifier() API on the Session's login.

James
  • 17,965
  • 11
  • 91
  • 146