-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hashcode generated by new hbm2java>too many entities load
PostPosted: Mon Apr 19, 2004 9:56 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 10:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
In the newest HibernateExt release, there is the <meta attribute="use-in-equals">true/false</meta> to controll which properties are used in equals/hashCode


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 10:37 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
Ehm, yes, but this has nothing to do with my case, I believe... I DO want those properties to get calculated in the hashcode, but in one case (the way hbm2java does) this causes 5 queries on the db, in the other (the way I do writing manually the code) this causes 3 queries.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.