Thread:
 fallback to object identiy 
 hengels   16 Feb 2004, 16:02 
 Re: fallback to object identiy 
 RobJellinghaus   26 Feb 2004, 19:13 
 Re: fallback to object identiy 
 hengels   15 Mar 2004, 15:06 
 Re: fallback to object identiy 
 Mr_Light   31 Jan 2006, 13:56 
 Re: fallback to object identiy 
 iwein   22 May 2007, 05:12 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: hengels (15 Mar 2004, 15:06) Replies: 1, Views: 37910
Subject: Re: fallback to object identiy
On 26 Feb 2004 19:13, RobJellinghaus wrote: 
 
>On 16 Feb 2004 16:02, hengels wrote:
 
>>what about using the primary key and fall back to object identity if
a 
>>pk is not assigned?
 
>This breaks collections because it changes the object's hashcode once
>you save it.  So you would get:
 
>UserManager u = session.load(UserManager.class, id);
 
>User newUser = new User("newUsername1");
>u.getUserSet().add(newUser); // adds a new Entity with id = null or
id = 0 
>session.save(newUser);
>session.flush();             // The id is now assigned to the newUser
object 
>if (!u.getUserSet().contains(newUser)) System.err.print("OOPS!");
 
>This *will* print "OOPS!" because newUser's hashcode changed when you
>saved it, so the userSet can no longer find it.
 
Huh! Then we need a rehash method on Set and Map ;-) ... or at least 
we could simulate a rehashing by removing and readding all entries.
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]