Hm well I don't really have any code for this since I am still planning this project. But say that you have a user with a name and a password and you wan't to be able to edit both. Then there is no good key so an id number would be needed. The easist way is to have the database generate this with using the native id settings in Hibernate. But say that you wan't to generate 10 Users put them in a set on some entity and store all by saving the entity. This would work as long as the hashcode does not depend on the id. Then you edit the username of one of those Users. Save the user and do a contains(editedUser) on the set. If the hashcode depends on the username this call will return false even though exactly the same object that is used in the contains(editedUser) call already is in the hashset. Since the hashCode() has changed. So this is clearly not the way to go...



Reply With Quote