DependencyInjectionInterceptor.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tradecloud.domain.infrastructure.persistence;

import org.hibernate.EmptyInterceptor;
import org.hibernate.type.Type;

import java.io.Serializable;

public class DependencyInjectionInterceptor extends EmptyInterceptor {

    private static final long serialVersionUID = 1L;

    private DomainObjectFactory factory;

    public DependencyInjectionInterceptor(DomainObjectFactory factory) {
        this.factory = factory;
    }

    @Override
    public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
        super.onLoad(entity, id, state, propertyNames, types);
        factory.injectDependencies(entity);
        return true;
    }
}