我正在寻找一种在运行时获取有关我的 hibernate 实体类的信息的方法。详细来说,我需要像
这样的信息Class ABC has the properties a, b and c with c being a list and association to class XYZ
为了类(class)
public class ABC {
private int a;
private String b;
@OneToMany
Private List<XYZ> c;
}
运行时所需的一切。我确信 Hibernate 在运行时知道所有这些,但我不知道如何获取这些信息。
最佳答案
如果您使用 Hibernate 作为 JPA 2 提供程序,那么您可以使用 JPA 2 元模型 ( javax.persistence.metamodel
)。这将从 JPA 元数据中为您提供有关 JPA 实体的信息:
entityManager.getMetamodel().entity(entityClass). getAttributes();
关于java - 在运行时获取有关实体的 hibernate 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5564955/