| [News.eclipse.technology.eclipselink] Re: JPA: adding entities to EntityManagerFactory programmatically |
Thanks, Rüdiger
I think this would be a useful enhancement to EclipseLink's JPA support, please log an enhancement request for it in Bugzilla.
In general, EclipseLink supports adding class dynamically through its' native persistence API, but not directly for the JPA API, as JPA does not support this.
However it should be possible to add JPA Entity classes on the fly. You can access the EclipseLink ServerSession from the EntityManagerFactoryImpl (getServerSession()), and use its' addDescriptor(ClassDescriptor) or addDescriptors() API to add EclipseLink ClassDescriptors. You will need to build the ClassDescriptors meta-data objects directly yourself (or use the Mapping Workbench to create them), as loading from JPA annotations or orm.xml would be more difficult.
There is also the issue of weaving the classes. Since they may have already been loaded, they will not be able to be weaved, so will not support lazy ToOne's or change-tracking unless you statically weave them, or use ValueHolders directly.
-- James