These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: strange many-to-many - is supported by hibernate? thanks
PostPosted: Wed Apr 06, 2005 7:19 am 
Beginner
Beginner

Joined: Tue Apr 05, 2005 12:09 pm
Posts: 48
Location: Slovakia (SK), Košice (KE)
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.