Hibernate does not guarantee the same object will be returned when you get the same record out of the database twice. You will get the same object if retrieved twice in the same session because the first object is placed into the session cache and Hibernate looks in the cache before creating a new object.

The Hibernate documentation recommends overriding equals() (and hashCode(), of course) to determine equality. (Ch. 24 of the Hibernate 3 manual: "Identify natural keys for all entities, and map them using <natural-id>. Implement equals() and hashCode() to compare the properties that make up the natural key.") There are folks in the user community who believe you should just compare on the database ID, though the documentation (and Hibernate In Action) recommends against that.

As a stopgap, you may want to mark your classes for caching (in EHCache); this cache will get checked before instantiating an object.

 ...Richard




On Jan 11, 2006, at 12:49, Jason Dyer wrote:

On Wednesday 11 January 2006 15:26, Michael Prescott wrote:
Are you able to use a debugger to see what's being compared by the
PropertySelection? It uses Java object identity as a first comparison,
so from your usage, the objects' equals() methods may not even be
involved.

Yes, what I see is:
(in renderFormComponent, line 92)
value = [EMAIL PROTECTED]
option = [EMAIL PROTECTED]

where value is customer.standing and option is the CustomerStanding object that should be the same object as it references the same database record.

I did not override the equals() method. Well, actually I tried that and got a NPE for my troubles. Then, I read further and it seems that the hibernate
folk do not recommend replacing equals()--and that doing so should be
unnecessary within the same session...

I'm wondering if you've made a mistake in your IPropertySelectionModel. Option, label and value are easy to mix up. The IPropertySelectionModel
Javadocs refer to the first of those as 'option value', which doesn't
help.

(The options are the underlying objects which are used by the
comparison, and label and value are used in the HTML.)

Yeah, it was a bit confusing, but I think I've got that part right, at least.

Thanks,
-Jason


Michael

--
In this vale
Of toil and sin
Your head grows bald
But not your chin.
                -- Burma Shave
--------------
Jason Dyer
BlueTarp Financial, inc.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to