-->
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: 'created' member and equals()/hashCode() in CaveatEmptor
PostPosted: Mon Oct 04, 2004 7:22 am 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
I noticed that several domain classes in the CaveatEmptor source have a
private Date created = new Date(); member that is used only in the equal() / hashCode() method.

For example the Category class has this member defined. Is the sole purpose of this to be easily be able to implement equals() for this class since implementing equals() for the Category class without the 'created' member would be rather involved and would require to compare parent categories recursively?

If this member was added only to be easily implement equals()/hashCode(), is this a pattern you recommend in cases where computing the business equality would turn out to be complicated or expensive? The overhead of this method obviously being an extra non-business 'created' field in the database table.

Thanks,
Sanjiv


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 7:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
LOL, no, it is there because the date something is created is an interesting item of data to keep in the database.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 4:40 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It's actually both: I wanted to show that in practice and real applications you have almost always entity attributes like "created", "created by" and other meta data. This is a often a good choice for the equals() implementation.

An equals() implementation for a plain Category would be involved, but again, a class with a single attribute is unrealistic in the real world.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.