Am Donnerstag, den 10.11.2005, 11:41 +0100 schrieb Thomas Dudziak: > On 11/10/05, werner <[EMAIL PROTECTED]> wrote: > > > I'm using OJB 1.0.3 with PB-API and it'S doing a great job. Now I'm > > looking for some information about the equals() and hashCode() methods: > > - In which cases should they be overwritten? > > In general it is a good idea to overwrite these methods because > persistent objects (read from/written to a database) tend to have > value semantics, e.g. two objects are not only equal if they are > identical (as with the default equals implementation), but rather if > they have the same state (field values). > > > - How can hashCode() be implemented? Can I use just the Primary Key for > > the hashcode, or does that cause problems? > > You should only do that if your app controls the pk values. If OJB or > the database creates them, then this will cause problems with > yet-unwritten objects which obviously don't have pk values yet.
Thanks for your answer. The hashCode function is a little mystery to me. I use a standard database setup where every table has a primary key (auto increment integer). Is it a proper solution to add the hashcode of all fields except the primary and return the result as the new hashcode of the object? What happens if I create 2 new objects with empty fields. They would always be considered as equal until I put some data into the object. So I think it wouldn't work. Werner > > Tom > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > Fischer & Masik OEG GEFi Informationstechnik und Datenservice Reisenbauerring 5/1/12 A-2351 Wiener Neudorf Tel: 02236 / 304 224 Fax: 02236 / 304 278 Mobil: 0676 528 97 57 Internet: http://www.gefi.at e-mail: persönlich: [EMAIL PROTECTED] allgemein: [EMAIL PROTECTED] ************************* Confidentiality Notice ************************* The information contained in this Email, and any attachments, is intended for the named recipients only. It may contain confidential and/or privileged information. If you are not the intended recipient, you must not copy, distribute, or take any action in reliance on it. Any views expressed do not necessarily reflect the views of the company. If you receive this Email by mistake, please advise the sender by using the reply facility in your Email software and then delete it.
