4
개체가 있습니다. 클래스가 Hibernate의 테이블에 매핑되는지 어떻게 알 수 있습니까?클래스가 Hibernate 엔티티로 매핑되어 있는지 어떻게 알 수 있습니까?
개체가 있습니다. 클래스가 Hibernate의 테이블에 매핑되는지 어떻게 알 수 있습니까?클래스가 Hibernate 엔티티로 매핑되어 있는지 어떻게 알 수 있습니까?
편집 : 원래의 대답은 작동하지만 바람직하지 않을 수 있습니다 unitialised 프록시를 초기화합니다.
더 나은 솔루션
boolean isHibernateEntity = sessionFactory.getClassMetadata(HibernateProxyHelper.getClassWithoutInitializingProxy(yourObject)) != null;
원래 답 : sessionFactory
없이 여기
boolean isHibernateEntity = sessionFactory.getClassMetdata(Hibernate.getClass(yourObject)) != null;
그리고 :
private boolean isEntityClass(Object o){
if(o != null){
Type[] interfaces = o.getClass().getGenericInterfaces();
for(Type interf : interfaces)
if(interf.equals(HibernateProxy.class))
return true;
}
return false;
}