Hi,
I am new to Hibernate and was facing lazyinitialization problems. To fix this I started using OpenSessionInViewFilter. I wrote my own filter which extends OpenSessionInViewFilter. For each request I am creating a session and closing it at the end. Due to this a new error has started occuring.
'org.hibernate.HibernateException: Found two representations of same collection'.
I am not sure why this is happening. Probably the method I have to used to resolve lazyinitialization itself is wrong. Could anyone please help me with it? Any ideas on the lazy initialization problem or the current problem would be greatly appreciated.
I have given below the code I have written for Session Filter.
Thanks & Regards
Ajay
-----------
/*
* The default mode is FlushMode.NEVER
*
* @see org.springframework.orm.hibernate.support.OpenSessionInViewFilter#getSession(net.sf.hibernate.SessionFactory)
*/
protected Session getSession(SessionFactory sessionFactory)
throws DataAccessResourceFailureException {
Session session = super.getSession(sessionFactory);
session.setFlushMode(FlushMode.COMMIT);
return session;
}
/**
* we do an explicit flush here just in case we do not have an automated flush
*/
protected void closeSession(Session session, SessionFactory factory) {
session.flush();
super.closeSession(session, factory);
}
|