We have this common code becuase we dont know entity defined in the persistence.xml belongs to which persistent unit. so iterate over entity managers to find out. Once we find out we assign entity manager and then interact with db with that em.
//em1 we got it from emf map Set<EntityType<?>> em1Entitites = em1.getMetamodel().getEntities(); Set<EntityType<?>> em2Entities = em2.getMetamodel().getEntities(); for (EntityType type : em1Entitites) { Class javaType = type.getJavaType(); //fnDO is passed entity if (javaType.getName().equals(fnDO.getClass().getName())) { em = em1; break; } } for (EntityType type : em2Entities) { Class javaType = type.getJavaType(); if (javaType.getName().equals(fnDO.getClass().getName())) { em = em2; break; } } Hope that will help to understand you more details. -- View this message in context: http://openjpa.208410.n2.nabble.com/Retrieving-POJO-using-Native-Query-tp6841951p6842045.html Sent from the OpenJPA Users mailing list archive at Nabble.com.