Quote:
Hibernate version: 2
Database: Oracle
Mapping documents:
<hibernate-mapping package="defi.tre.komodo.type.hibernate">
<class name="HibernateWarrant" table="TWRTKOM">
<id column="ID" name="id" type="integer" length="22">
<generator class="assigned"/>
</id>
<property column="NAME" name="name" type="string"/>
<property column="AGE" name="age" type="integer"/>
<property column="PLACE_ID name="placeId" type="integer"/>
<property code but how? >
use a one-to-many ?
<set role="code">
<key column="place_id"/>
<one-to-many class="integer"/>
</set>
</class>
</hibernate-mapping>
Hi!
First, I know that there is no way to map a class to multiple tables in Hibernate 2 (and I can't use Hib3, 'cause the managers fears the "beta" state of the release, too bad... ). So, I just wanted to know a way to write my mapping.
Here is a description:
My warrant has a name, an age, and a code associated with it. The code depends of the place where my warrant live.
The table of the warrant is:
Code:
create table TWRTKOM(
ID NUMBER(22) not null,
NAME VARCHAR2(100),
AGE NUMBER(22),
PLACE_ID NUMBER(22));
the table with the codes is:
Code:
create table TPLCKOM(
PLACE_ID NUMBER(22),
INTERNET_CODE VARCHAR(100));
My POJO is:
Code:
class Warrant {
Long id;
String name;
Integer age;
String code;
Integer codeId;
}
Please, do you know any way to do this kind of mapping?
One of the difficulty is that the code depends on the placeId, and not the warrant id, so there is no one-to-one mapping between warrant table and code table.
The second difficulty is that I want to avoid, if possible, to create a class containing just the code, and the corresponding mapping. So a one-to-many mapping seems a bit too much for this problem, (since there is only one code, not a collection of codes, and since I need to create a wrapping object just containing the fields "id" and "code").
The last little thing is that I want to avoid putting the code directly in the warrant, because I already have the code table, and I can't change it.
It is like getting the property code from another table, depending on the value of the placeId.
I can change the warrant table , if there is a better database design for this problem, but I can't change the code table.
(Sorry for my bad english writing)
Thanks!
Cyril