Hi,
have two tables one is called Mitgliedr and one is MitgliedHistory that has an additional
version counter. When I try to save a member instance I'ld like to have a copy with a version counter in the mitglied_history table. I always receive an exception saying:
HibernateException: identifier of an instance of de.guug.mv.data.MitgliedHistory altered from de.guug.mv.data.MitgliedHistory@1d686c1 to de.guug.mv.data.MitgliedHistory@1d686c1
My code is:
public void storeMitglied(Mitglied mitglied) throws Exception {
MitgliedHistory history = new MitgliedHistory();
this.copyIMitgliedForm(mitglied, history);
this.copyMitgliedUnconverted(mitglied, history);
session.saveOrUpdate(mitglied);
history.setNr(mitglied.getNr());
session.save(history);
}
The mapping of the MitgliedHistory Class is:
<class
name="de.guug.mv.data.MitgliedHistory"
table="mitglieder_history"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id>
<key-property name="nr" column="nr" />
<key-property name="version" column="version"/>
</composite-id>
<property
name="alias"
type="java.lang.String"
update="true"
insert="true"
column="alias"
/>
<property
name="aliasValid"
type="boolean"
update="true"
insert="true"
column="alias_valid"
/>
<property
name="bank"
type="java.lang.String"
update="true"
insert="true"
column="bank"
/>
<property
name="betrag"
type="java.lang.Integer"
update="true"
insert="true"
column="betrag"
/>
<property
name="bezahlinfo"
type="java.lang.String"
update="true"
insert="true"
column="bezahlinfo"
/>
<property
name="blz"
type="java.lang.String"
update="true"
insert="true"
column="blz"
/>
<property
name="buchungshinweis"
type="java.lang.String"
update="true"
insert="true"
column="buchungshinweis"
/>
<property
name="dr"
type="boolean"
update="true"
insert="true"
column="dr"
/>
<property
name="duName"
type="java.lang.String"
update="true"
insert="true"
column="du_name"
/>
<property
name="eintritt"
type="java.sql.Timestamp"
update="true"
insert="true"
column="eintritt"
/>
<property
name="email"
type="java.lang.String"
update="true"
insert="true"
column="email"
/>
<property
name="emailValid"
type="boolean"
update="true"
insert="true"
column="email_valid"
/>
<property
name="ermaessigungsgrund"
type="java.lang.String"
update="true"
insert="true"
column="ermaessigungsgrund"
/>
<property
name="fax"
type="java.lang.String"
update="true"
insert="true"
column="fax"
/>
<property
name="firma"
type="java.lang.String"
update="true"
insert="true"
column="firma"
/>
</class>
I' currently using version 2.1.1
Actually I'm a little bit confused by this exception message, because it seems that the class id is the same. I already played around with the mapping, I'ld also like to use the
<version> tag for my version field. But then I cannot use the version field also as part
of the compound-id.
Does my exceptions have something to do with the override hashCode function, that is right now just super.hashCode(); ?
Any ideas?
Another issue is that I'ld would like to inherit the history class from the normal class in order no to copy code. But I'ld also like to use the Xdoclet tags. But that causes trouble,
because the parent class has a different primary key.
thanks in advance
Michael
|