Hibernate version: 3
Name and version of the database you are using: Oracle 9
Hello
Please help me solve this problem with mapping. I have 3 tables - "book", "message", "language".
Each book in table "book" has title and description specified by "title_key_id" and "description_key_id" attributes. Theese are not defined as foreign keys, because they refer to non unique attribute "key_id" in table "message". The "key_id" and "language_id" creates composite primary key for table "message". Message contains all titles and descriptions in every defined language. Language is spefigied by foreign key "language_id". There are defined eg. 3 languages in the table "language" (eg. EN, DE, SK). The tables were created like this:
Code:
CREATE TABLE language (
language_id NUMBER NOT NULL,
code VARCHAR(3) NOT NULL,
name VARCHAR(32) NOT NULL,
CONSTRAINT language_pk PRIMARY KEY (language_id)
);
CREATE TABLE message (
language_id NUMBER NOT NULL,
key_id NUMBER NOT NULL,
CONSTRAINT message_pk PRIMARY KEY (language_id, key_id),
CONSTRAINT language_fk FOREIGN KEY (language_id) REFERENCES language (language_id)
);
CREATE TABLE book (
book_id NUMBER NOT NULL,
title_key_id NUMBER NOT NULL,
description_key_id NUMBER NOT NULL,
...
CONSTRAINT object_p" PRIMARY KEY (object_id)
);
All I want is to have a class Book with a properties titleMessages and descriptionMessages of type Map, where key would be language_id. So my question is - what is the relation "book" to "message"? It seems to me like some strange many-to-many? I couldn't find any suitable hibernate mapping. Is my database design allright?
There is one idea that came up to me - create one more table "message_key" containing only one attribute "key_id" that would be also a primary key. Then in the table "book" each attribute "title_key_id" and "description_key_id" sould be a foreign key referencing to that "message_key" table. The "key_id" in the "message" table would be foreign key too.
Please help me to decide which design is correct and how to map "book" to "message". I would be most happy if I could map my existing (first) db design by hibernate.
Thanks a lot
Martin