Getting sleep information for users at runtime

I am looking for a way to get information about my runtime hibernation classes. In details I need information like

The class ABC has properties a, b, and c, where c is a list and an association with class XYZ

for class

public class ABC { private int a; private String b; @OneToMany Private List<XYZ> c; } 

All that is needed at runtime. I'm sure Hibernate knows all this at runtime, but I don't know how to get this information.

+4
source share
4 answers
 PersistentClass userMapping = cfg.getClassMapping(ABC.class); 

cfg is an instance of the Hibernate configuration.

PersistentClass contains all the necessary information.

+3
source

If you use Hibernate as a provider of JPA 2, you can use the JPA 2 metamodel ( javax.persistence.metamodel ). This will give you information about your JPA entities from the JPA metadata:

 entityManager.getMetamodel().entity(entityClass). getAttributes(); 
+2
source

It seems that reflection is what you need, its not sleeping specific information, which you seem to be after. You just need information about which fields the class has and what types they are ...

0
source

You can get this information using reflection.

 Class abcClass= ABC.class; Field[] fields = abcClass.getDeclaredFields(); 
0
source

Source: https://habr.com/ru/post/1346901/


All Articles