meissa I don't think you understood my message correctly. Your dao is fine - it simply delegates all your calls to HibernateTemplate - the dao or the mapping is not the problem.
Let's call Structure class A and StructureSocieteGenstion class B. B has 1-to-many relation with B.
When you are using eager fetching you are retrieving eagerly (you initialize) the B and associated A set relationship within that session.
However, if you use only the DAO for A, then the object that you retrieve even if it's the same as one associated with B which was retrieved before, it's a proxy (not initialized). Because proxies depend on their session, the object cannot be rezolved unless the session is open. That's why, you are able to find the object but when you use it, you get an exception, the associated session was closed (that's why I mentioned looking at OpenSessionInView).
Try as a quick hack, inside your DAO to initialize the object like this:
Code:
public Structure findById(String codeStructure) throws FinderException
{
Structure result=null;
try
{
result=(Structure)getHibernateTemplate().load(Structure.class,codeStructure);
// initialize object
Hibernate.initialize(result);
}
catch (Exception e)
{
String errorMessage=" Echec du chargement de la structure"+codeStructure;
log.error(e+errorMessage);
throw new FinderException(errorMessage,e);
}
return result;
}
Another alternative would be to use the OpenSessionInView interceptor/filter.
As I said before, load() returns proxies if lazy is set to true while find() always returns entites.