Have one really simple part of your equals method that compares db id's, and if one of them isn't set, alternatively compare whatever else is available. (not ~everything~, just enough to give you uniqueness, if that's possible :) )
On 4/5/06, Rob Dennett <[EMAIL PROTECTED]> wrote: > > The Hibernate documentation recommends implementing equals and hashCode > using an objects business key rather than the database id. Kent Tong in his > excellent book _Enjoying Web Development with Tapestry_ implements equals > using all fields of his example object, including the field which contains > the database id and fields which are not part of the business key, in order > to deal with concurrency issues. The issue with using the database id as > part of the equals method is that it prevents you from adding an unpersisted > object to a set. The problem with using fields that are not part of the > business key is that if the object points to a large graph, the compare can > be deep and expensive in terms of processing time. The problem with not > using the id field and non-business key fields is that you can't compare a > database instance with its cached copy to see if it has changed before > committing changes. So what should you do here? > > > > Thanks for your help, > > Rob > > > -- > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.1.385 / Virus Database: 268.3.5/301 - Release Date: 4/4/2006 > > > -- Jesse Kuhnert Tacos/Tapestry, team member/developer Open source based consulting work centered around dojo/tapestry/tacos/hivemind. http://opennotion.com