英文:
Search for java class using reflection with persistence unit
问题
我想使用持久化单元(persistence unit)和反射(reflection)来搜索一个Java类。现在我正在使用包名进行搜索。
Reflections reflections = new Reflections("com.entites");
Set<Class<? extends Object>> allClasses = reflections.getTypesAnnotatedWith(Entity.class);
英文:
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
得分: 0
如果您有持久化单元,那么您就有类名(位于 <class>...</class> 内),并且您可以使用 Class.forName("com.entites.MyEntity") 获取 Class 对象。
例如,如果必要的话,您可以以编程方式读取 persistence.xml 文件。
我猜想持久化单元名称(<persistence-unit name="...">)与反射无关。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论