Hi,
I hope I don't ask something which has been answered several times.
I am using the PersistenceBroker API (RC1.4) for some time and noticed a
problem if I want to implement equals() and hashCode() in my business
classes. For example:
Class HerstellerImpl {
String bezeichnung;
..
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null) {
return false;
}
if (o.getClass() != this.getClass()) {
return false;
}
HerstellerImpl h = (HerstellerImpl) o;
if (!this.getBezeichnung().equals(h.getBezeichnung())) {
return false;
}
return true;
}
// hashCode() in the same manner
}
Mapping Definition:
<!-- Definitions for de.jas.kassart.model.HerstellerImpl -->
<class-descriptor
class="de.jas.kassart.model.HerstellerImpl"
table="HERSTELLER"
>
<field-descriptor
name="_id"
column="ID"
jdbc-type="SMALLINT"
primarykey="true"
autoincrement="true"
access="anonymous"
/>
<field-descriptor
name="bezeichnung"
column="BEZEICHNUNG"
jdbc-type="CHAR"
/>
</class-descriptor>
Now if I want to store an object which has already been stored and
which's bezeichnung has changed, OJB produces an insert statement
instead of an update statement.
I am not sure but I think the reason is that Identity(object, broker,
cld) does retrieve a new database key because AbstractPersistentField
uses a HashMap for storing objects. After changing bezeichnung equals()
and hashCode() produce new entries in this Map.
Has anybody had the same problems? Have I misunderstood something? Thank
you for every help!
Andreas Marx