I've found the problem, and I think it should be resolved in hibernate :
If a super class of a persistant subclass, has a map with public getter & setter, and if the subclasses overloads only the getter, then the map isn't lazy enabled.
Just overloading the setter in the subclass fixes the problem.
I use this configuration because I use XDoclet, and I need only the getter in the subclass to specify the mapping parameters.
Code:
class A{
protected Map<String,ImageOrFile> attachements;
/**
* @hibernate.collection-key column="parent_post_unid"
* @hibernate.collection-index column="key" type="string"
* @hibernate.collection-composite-element class="com.seanergie.persistence.ImageOrFile"
*/
public Map<String,ImageOrFile> getAttachements(){
return attachements;
}
public void setAttachements(Map<String,ImageOrFile> attachements) {
this.attachements = attachements;
hasAttachement = attachements != null && !attachements.isEmpty();
}
}
/**
* @hibernate.class table="forum3"
*/
class B extends A{
/**
* @hibernate.map table="forum_attachements" lazy="true" cascade="all"
*/
@Override
public Map<String,ImageOrFile> getAttachements(){
return attachements;
}
// ************ PROBLEM HERE ***********************************
// the map isn't lazy if this settter isn't overloaded in B
public void setAttachements(Map<String,ImageOrFile> attachements) {
super.setAttachements( attachements );
}
}
I guess the conditions to check if the map can be lazy don't check the super class to see if it has the setter, and so it believes there is no setter, so the map can't be lazy.
Also, with hibernate 2, there used to be some notification at startup when for some reasons lazy loading can't be used. Now, hibernate 3.0.2, goes through this silently. Is there some way to see those warnings ?
It would have saved me a few days of debuging.
Thanks,
Sylvain.
P.S. If nobody objects, I'll add a bug to the JIRA database for this problem.