We are currently struggling with the way hbm2java in extensions 2.1 implements hashCode. The problem is we have a couple of composite id-s, where the automatically implemented hashcode uses the composite-id elements.
The problem is we would like those elements to be lazy classes: in every one of them, the hashcode is simply based on their unique id, but it seems that when the hashcode for the composite is calculated, those objects are loaded even if their id should be present in the proxy. Is this true? Shouldn't it be possible to call store.getStoreId() on the proxy without the actual object being loaded?
As an example, if we use the standard hashcode generated by hbm2java
public int hashCode() {
return new HashCodeBuilder()
.append(getStore())
.append(getProduct())
.append(getChannel())
.toHashCode();
}
our HQL query translates in 5 queries, with the store and channel entities that get loaded even if we don't want them to. Although if we overwrite the generated hashcode by:
public int hashCode() {
return new HashCodeBuilder()
.append(getStore().getStoreId())
.append(getProduct().getProductId())
.append(getChannel().getChannelId())
.toHashCode();
}
the queries are only three and store and channel are not loaded.
What is strange is that the hashcode method for store is
public int hashCode() {
return new HashCodeBuilder()
.append(getStoreId())
.toHashCode();
}
(and the same is for channel), so there should be no need to load them (or at least no more need than there is in the getStore().getStoreId() version of the hashcode. Is this an error in our approach?
Anyway: if changing this is not possible, we would like to turn OFF the automatical generation of hashcode for the composite-id, since we need to replace it with the form with the ids in place of the normal objects (put in a class-code meta). Apparently this is not possible, and we are forced to a manual delete of the generated hashcode in order to prevent the duplication in the class and the compilation error.
Thanks,
Davide Baroncelli.
|