Try this bro,
Code:
public interface PostLoadHibernateCallback
{
public Object postLoad(Object entity, Session session);
}
public class UserDaoImpl extends HibernateDaoSupport
{
@SuppressWarnings("unchecked")
public User getUserByPrimaryKey(final Class clazz, final Long pk,
final PostLoadHibernateCallback callback, final LockMode lockMode)
{
if (clazz == null)
throw new IllegalArgumentException("clazz can not be null");
return (User) this.getHibernateTemplate().execute(new HibernateCallback()
{
public Object doInHibernate(Session session) throws HibernateException
{
User user = null;
if (lockMode != null)
{
user = (User) session.get(clazz, pk, lockMode);
return callback.postLoad(obj, session);
}
else
{
user = (User) session.get(clazz, pk);
return callback.postLoad(obj, session);
}
}
}, true);
}
}
You can access roles collection of user class in postLoad method of callback interface or if you dont like this interface thingy then do your stuff in doInHibernate method, and thats it....
Cheers,
Imran Sarwar