Search for java class using reflection with persistence unit

348 Views Asked by At

I want to search for a Java class using reflection with persistence unit. Now I'm using the search with the package name

Reflections reflections = new Reflections("com.entites");
Set<Class<? extends Object>> allClasses = reflections.getTypesAnnotatedWith(Entity.class);
1

There are 1 best solutions below

0
On BEST ANSWER

If you have persistense unit then you have classes names (inside <class>...</class>) and you can get Class objects using Class.forName("com.entites.MyEntity").

For example you can programmatically read persistence.xml file if necessary.

I guess persisent unit name (<persistence-unit name="...">) is irrelevant to reflections.