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);
Showing posts with label entitymanager. Show all posts
Showing posts with label entitymanager. Show all posts
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 :
Labels:
entity,
entitymanager,
entitymanagerfactory,
jpa,
metamodel
Subscribe to:
Posts (Atom)