Metamodel meta = entityManagerFactory.getMetamodel(); // or Metamodel meta = entityManager.getEntityManagerFactory().getMetamodel(); // to iterate over all classes for (EntityType<?> e : meta.getEntities()) { // get entity class Class c = e.getJavaType(); // get entity name as string String entityName = e.getName(); //or c.getName() } // test a particular class is entity // will throw java.lang.IllegalArgumentException if not an entity meta.entity(inputClass);
Friday, March 16, 2012
Listing all entities in a JPA
Sometimes it may be a usecase scenario to find whether a particular class is an entity managed by persistence context. If you have entityManager or entityManagerFactory you can easily do that :
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment