Getting a list of all the entity class names

#1

I was wondering if there is any way to get a list of the entity names in the database?

#2

You can use the Metamodel API as explained by the JPA Metamodel API page in the manual.

ObjectDB Support
#3

Actually, there is a simpler way to get the class names (in one line of code).

It requires a JDO' s PersistenceManager:

  String[] classNames = com.objectdb.Utilities.getClassNames(pm);

In JPA you have to unwrap the EntityManager as a JDO PersistenceManager:

  String[] classNames =
      com.objectdb.Utilities.getClassNames(em.unwrap(PersistenceManager.class));

This method remained from ObjectDB 1.x, but in JPA 2 applications the JPA Metamodel API should be preferred because it is portable and provide better functionality (for example you can use it to get entity names or class names - which is not the same).

ObjectDB Support

Reply