Hibernate version:
V3
Name and version of the database you are using:
IBM DB2 v7
We are encountering trouble mapping a mildly denormalized database. By "mildly" I mean there is no duplicated data but tables are combined to reduce the number of queries. I have seen similar denormalization at a few companies so we can't be alone in having to deal with it. I don't see the questions in the discussion list or FAQ.
1. Class A 1 -1 with an optional class B where class B is an inheritance tree. The database represents both classes as columns in the same table. A simplified definition would be:
create table AB
(
A1 INTEGER, --- key
A2 char(50),
BDISCRIMINATOR char(1),
B2 char(30),
B3 INTEGER
)
In other parts of the system where we have the inheritance mapped to its own table and Hibernate works great. Obviously Hibernate is built to handle the mapping when the B classes are in their own table, but is there a way to map this table to our classes?
2. Class C is 1-many (actually up to 5) with class D. Any Java Collection is workable for us. Not my preference, but the DBA wants to avoid another query. The simplified table looks like:
create table CDDDDD
(
C1 INTEGER, --- key
C2 DATE,
C3 char(30),
DDESC1 char(30),
DAPPLIES1 char(1),
DAMOUNT1 FLOAT,
DFREQUENCY1 INTEGER,
.....
DDESC5 char(30),
DAPPLIES5 char(1),
DAMOUNT5 FLOAT,
DFREQUENCY5 INTEGER
)
Again, with two tables Hibernate would handle this fine. We considered maintaining a list for our purposes and creating 20+ field accessors that would present a flat version of the java model purely for Hibernate's usage. Is there a clean way to handle this?
Thanks
|