Hibernate version: 3.1.3
I'm having a problem with a class Contract that has many mapped Sets, e.g.:
Code:
/**
* @hibernate.set lazy="true" inverse="true"
* @hibernate.collection-key column="cntr_id"
* @hibernate.collection-one-to-many class="com.jnj.eicd.model.DocumentHistory"
*/
public Set getDocumentHistory() {
return documentHistory;
}
public void setDocumentHistory(Set documentHistory) {
this.documentHistory = documentHistory;
}
/**
* @hibernate.set lazy="true" inverse="true"
* @hibernate.collection-key column="cntr_id"
* @hibernate.collection-one-to-many class="com.jnj.eicd.model.ContractVariable"
*/
public Set getContractVariables() {
return contractVariables;
}
public void setContractVariables(Set contractVariables) {
this.contractVariables = contractVariables;
}
Both are bidirectional, and at the other end both associations are mapped as such:
Code:
/**
* @hibernate.many-to-one column="cntr_id" class="com.jnj.eicd.model.Contract"
*/
public Contract getContract() {
return contract;
}
public void setContract(Contract contract) {
this.contract = contract;
}
These are just two of 22 mapped Sets in Contract.java. Most of these sets are fetched correctly. When I do a getContractVariables().size(), the generated SQL fetches no more than is necessary.
However, when I do a getDocumentHistory().size(), it follows the association in DocumentHistory back to Contract and thuis joins with Contract again, resulting in a 466 line SQL query (after formatting in TOAD), where it could be done in much, much less. It does this with at least 4 of the other Sets as well. This results in a major slowdown of the application.
I can't see any difference in mapping between those that work correctly and those that don't. If anyone could point me in a right direction as to where to look, I'd be much obliged.