i'm trying to achieve the following behaviour with hibernate (2.1.3) and a
mysql database (4.x): several tables should share some kind of an unique
identifier, (called "uniqueid" for example) which can be used as refernce to
any kind of data in any table.
the mapping:
Code:
<class name="User" table="user">
<id name="uid" column="uid" type="long" unsaved-value="-1">
<generator class="native"/>
</id>
<property ... >
<many-to-one name="uniqueID" class="UniqueObject" column="uniqueid" not-null="true" unique="true"/>
</class>
---
<class name="Blah" table="blah">
<id name="blahid" column="blahid" type="long" unsaved-value="-1">
<generator class="native"/>
</id>
<property ... >
<many-to-one name="uniqueID" class="UniqueObject" column="uniqueid" not-null="true" unique="true"/>
</class>
---
<class name="UniqueObject" table="uniqueobject">
<id name="uniqueid" column="uniqueid" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
</class>
i'll have another table called "log" which holds the uniqueid as primarykey
and a timestamp as a data column, therefore i can insert a row into the
"log"-table for every row in the "users" table and another one for every
row in the "blah" table. (i haven't figured out the hibernate mapping for
the "log" table but thats not my primary concern).
the only thing missing is the automatic generation of an entry in the table
"UniqueObject" every time i insert a "user" object.
can hibernate provide such a behaviour or do i have to alter my classes
to insert the row manually.
thanks in advance
art