1

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);
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

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.

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66