import org.hibernate.event.PostLoadEvent;
import org.hibernate.event.PostLoadEventListener;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
public class SpringHibernateInjector implements PostLoadEventListener, BeanFactoryAware{
AutowireCapableBeanFactory beanFactory;
public void onPostLoad(PostLoadEvent event) {
Object hibernateObject = event.getEntity();
beanFactory.autowireBeanProperties(hibernateObject, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
}
public void setBeanFactory(BeanFactory factory) {
beanFactory = (AutowireCapableBeanFactory) factory;
}
}