org.javers.hibernate.HibernateUnproxyObjectAccessHook Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-hibernate Show documentation
Show all versions of javers-hibernate Show documentation
JaVers object auditing and diff framework
package org.javers.hibernate;
import org.hibernate.Hibernate;
import org.hibernate.proxy.HibernateProxy;
import org.javers.core.graph.ObjectAccessHook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HibernateUnproxyObjectAccessHook implements ObjectAccessHook {
private static final Logger logger = LoggerFactory.getLogger(HibernateUnproxyObjectAccessHook.class);
public T access(T entity) {
if (entity instanceof HibernateProxy) {
Hibernate.initialize(entity);
HibernateProxy proxy = (HibernateProxy) entity;
T unproxed = (T) proxy.getHibernateLazyInitializer().getImplementation();
logger.info("unproxying instance of " + entity.getClass().getSimpleName() + " to " + unproxed.getClass().getSimpleName());
return unproxed;
}
return entity;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy