简体   繁体   中英

JPA [Eclipselink] - How to refresh metadata of Dynamic entities created?

I got to know about possibility of Dynamic entity creation in eclipselink from here . And I'm trying to create Dynamic entities and map them to static entities which are already present in the same persistence unit as described in the examples given here .

I'm using refreshMetadata(with empty map of properties) of EntityManagerFactoryImpl to refresh metadata. But the the dynamic entities are not getting listed in the metamodel of entitymanager factory.

Can somebody let me know where am I going wrong?

I expect they won't, as the Dynamic entity api adds mappings to the native EclipseLink session, while the JPA metamodel is build from JPA mappings. refreshMetadata is used to rebuild the native EclipseLink session using any new JPA metadata (orm.xml etc), but does not go the other way.

I was able to refresh the metamodel by adding a new metamodel with the current session by the following code snippet:

    Metamodel metamodel = new MetamodelImpl((AbstractSession) dynamicHelper.getSession());
    ((EntityManagerFactoryImpl) emf).setMetamodel(metamodel);

Though this didn't solved my main problem, it solved the problem I've asked here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM