Search in sources :

Example 1 with ToOneDelegateSessionImplementor

use of org.hibernate.envers.internal.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor in project hibernate-orm by hibernate.

the class EntityInstantiator method replaceNonAuditIdProxies.

@SuppressWarnings({ "unchecked" })
private void replaceNonAuditIdProxies(Map versionsEntity, Number revision) {
    final Map originalId = (Map) versionsEntity.get(enversService.getAuditEntitiesConfiguration().getOriginalIdPropName());
    for (Object key : originalId.keySet()) {
        final Object value = originalId.get(key);
        if (value instanceof HibernateProxy) {
            final HibernateProxy hibernateProxy = (HibernateProxy) value;
            final LazyInitializer initializer = hibernateProxy.getHibernateLazyInitializer();
            final String entityName = initializer.getEntityName();
            final Serializable entityId = initializer.getIdentifier();
            if (enversService.getEntitiesConfigurations().isVersioned(entityName)) {
                final String entityClassName = enversService.getEntitiesConfigurations().get(entityName).getEntityClassName();
                final Class entityClass = ReflectionTools.loadClass(entityClassName, enversService.getClassLoaderService());
                final ToOneDelegateSessionImplementor delegate = new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision, RevisionType.DEL.equals(versionsEntity.get(enversService.getAuditEntitiesConfiguration().getRevisionTypePropName())), enversService);
                originalId.put(key, versionsReader.getSessionImplementor().getFactory().getMetamodel().entityPersister(entityName).createProxy(entityId, delegate));
            }
        }
    }
}
Also used : ToOneDelegateSessionImplementor(org.hibernate.envers.internal.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor) LazyInitializer(org.hibernate.proxy.LazyInitializer) Serializable(java.io.Serializable) Map(java.util.Map) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Aggregations

Serializable (java.io.Serializable)1 Map (java.util.Map)1 ToOneDelegateSessionImplementor (org.hibernate.envers.internal.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor)1 HibernateProxy (org.hibernate.proxy.HibernateProxy)1 LazyInitializer (org.hibernate.proxy.LazyInitializer)1