I would like to inject on all session.save() like below.
public class MyHbnSession implements Session {
@Override
public Serializable save(Object obj) throws HibernateException {
if(obj instanceof MyClass) {
MyClass mc = (MyClass) obj;
mc.setVal("Injected Prop");
}
return super.save(obj);
}
}
And then whenever i getSession i should receive my custom session object
MyHbnSession session = HibernateUtil.getSessionFactory().openSession();
I could not find how to do this with hibernate. And two major things i miss
- org.hibernate.Session is an interface and org.hibernate.impl.SessionImpl is the actual implementation. But in this case the session is implemented
- How to tell hibernate that this is our custom session implementation and this should be used by the session factory
Kindly throw me some light on what i'm missing. Thanks for any help.
PS : I can do it with aspectj but don't want to due to many reasons.