I managed to solve the problem.
If anyone is interested, fllowing is the code:
my custom interceptor class:
/*
* MyInterceptor.java
*
* Created on 25 June 2006, 16:24
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package intercept;
import domain.CustomUser;
import java.io.Serializable;
import java.util.Iterator;
import org.hibernate.CallbackException;
import org.hibernate.EntityMode;
import org.hibernate.Interceptor;
import org.hibernate.Transaction;
import org.hibernate.type.Type;
/**
*
* @author Dharshana
*/
public class MyInterceptor implements Interceptor {
/** Creates a new instance of MyInterceptor */
public MyInterceptor() {
}
public boolean onLoad(Object object, Serializable serializable, Object[] object0, String[] string, Type[] type) throws CallbackException {
return false;
}
public boolean onFlushDirty(Object object, Serializable serializable, Object[] object0, Object[] object1, String[] string, Type[] type) throws CallbackException {
return false;
}
public boolean onSave(Object object, Serializable serializable, Object[] object0, String[] string, Type[] type) throws CallbackException {
return false;
}
public void onDelete(Object object, Serializable serializable, Object[] object0, String[] string, Type[] type) throws CallbackException {
}
public void preFlush(Iterator iterator) throws CallbackException {
}
public void postFlush(Iterator iterator) throws CallbackException {
}
public Boolean isTransient(Object object) {
return null;
}
public int[] findDirty(Object object, Serializable serializable, Object[] object0, Object[] object1, String[] string, Type[] type) {
return null;
}
public Object instantiate(String string, EntityMode entityMode, Serializable serializable) throws CallbackException {
return new CustomUser((Long) serializable);
}
public String getEntityName(Object object) throws CallbackException {
return null;
}
public Object getEntity(String string, Serializable serializable) throws CallbackException {
return null;
}
public void afterTransactionBegin(Transaction transaction) {
}
public void beforeTransactionCompletion(Transaction transaction) {
}
public void afterTransactionCompletion(Transaction transaction) {
}
}
class CustomUser extends User{
public CustomUSer(){}
public CustomUser(Long id){
setId(id);
}
}
in the spring mapping file:
<property name="entityInterceptor"><ref local="dependencyInjectionInterceptor"/></property>
<bean id="dependencyInjectionInterceptor"
class="intercept.MyInterceptor"
>
</bean>
But there is a new problem now:
when saving the data, hibernate throws persistance exception because it cant find the persistor for the derived customuser class, im thinking of extending the sessionimpl.java to get around it.. not sure whether it is going to be a good idea though :)
Fixed the above problem by implementing the public String getEntityName(Object object) throws CallbackException in my interceptor.. So thats done i guess
_________________ Thanks,
Dharshana
|