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);
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.