-->
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.  [ 2 posts ] 
Author Message
 Post subject: Does any one have HashCodeBuilder for hibernate POJOs ?
PostPosted: Wed Mar 16, 2005 7:09 pm 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
Hi

I am using Hibernate 2.1, Middlegen 2.1 with Oracle 9i. I have a link table which only has a composite key made up of 3 primary keys. This link table does not have any other columns.

I am also using Velocity template to generate POJOs. The problem I am facing has to do with hash code generated for two rows of this link table. The hashcode comes out to be exactly same as a result I get only one row back from this table. Following is a code for Hashcode generation:

public int hashCode() {
HashCodeBuilder hcb = new HashCodeBuilder(17, 37)
#foreach($field in $clazz.getFields())
#if ( $field.getClassType().inJavaLang() || $field.getClassType().isPrimitive() || $field.getClassType().getPackageName().equals("java.math") || $javaTool.getTrueTypeName($field, $class2classmap).equals("java.util.Date") )

.append($field.getFieldName() )
#end
#end

;

return hcb.toHashCode();
}

As this link table doe snot have any other columns, nothing gets appended and hashcode is same all the time. Has anyone come across this and built their own better version of hashcode ?

Thanks a lot.
Ron


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 7:35 pm 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
Actually I realized that the hashcode is generated using column values to uniquely distinguish the object. As stated in my previous post, my table does not have any attributes just primary keys of 3 tables which in turn are 3 objects in the link table's POJO.

The collection of this link table is stored as 'Set' in the parent table and Set does not allow duplicate objects.

Can someone suggest any solution to this ?

Thanks
Ron


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.