Search in sources :

Example 1 with EntityNameResolver

use of org.hibernate.EntityNameResolver in project hibernate-orm by hibernate.

the class AnyType method guessEntityPersister.

private EntityPersister guessEntityPersister(Object object) {
    if (scope == null) {
        return null;
    }
    String entityName = null;
    // this code is largely copied from Session's bestGuessEntityName
    Object entity = object;
    if (entity instanceof HibernateProxy) {
        final LazyInitializer initializer = ((HibernateProxy) entity).getHibernateLazyInitializer();
        if (initializer.isUninitialized()) {
            entityName = initializer.getEntityName();
        }
        entity = initializer.getImplementation();
    }
    if (entityName == null) {
        for (EntityNameResolver resolver : scope.resolveFactory().getMetamodel().getEntityNameResolvers()) {
            entityName = resolver.resolveEntityName(entity);
            if (entityName != null) {
                break;
            }
        }
    }
    if (entityName == null) {
        // the old-time stand-by...
        entityName = object.getClass().getName();
    }
    return scope.resolveFactory().getMetamodel().entityPersister(entityName);
}
Also used : LazyInitializer(org.hibernate.proxy.LazyInitializer) EntityNameResolver(org.hibernate.EntityNameResolver) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Aggregations

EntityNameResolver (org.hibernate.EntityNameResolver)1 HibernateProxy (org.hibernate.proxy.HibernateProxy)1 LazyInitializer (org.hibernate.proxy.LazyInitializer)1