-->
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.  [ 3 posts ] 
Author Message
 Post subject: One-to-one mapping, collection
PostPosted: Wed Nov 10, 2004 12:40 pm 
Newbie

Joined: Wed Nov 10, 2004 12:27 pm
Posts: 10
Location: Düsseldorf, Germany
Hi,

I have a mapping-problem with hibernate. Let me explain the situation. I have an Entity-class and an EntityDescription-class. The entity class stores general entity information while within EntityDescription there are descriptions and titles for entities stored for several languages. EntityDescription consists of two Maps: titles and descriptions. An entity must not have a description for every possible language. So, the relation between Entity and EntityDescription is composition.

My idea for the database schema is that there is an entity and an entity_description table. entity_description has a composite key consisting of an reference to the entity-key and the iso language code. Therefore, a description object maps to several table rows. My problem now is that I can't find a way mapping my objects to a proper database schema, especially not with xdoclet. So far I found out, that composite-keys aren't supported by hibernate 2.1.6. But the main problem is that I cannot create a meaningful db-mapping.

Thanks for your hints in advance,
Christian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 10, 2004 9:47 pm 
Beginner
Beginner

Joined: Sun Oct 03, 2004 8:50 am
Posts: 32
Location: McLean, VA
First, one quick note, composite keys ARE supported in Hibernate 2.1.6, they are NOT however supported in the current version of XDoclet, which is a pain in it's own right.

I'm not sure I understand exactly what you're trying to do but let me take a shot.

First, create your entity table with whatever you need in it with a some primary key that has nothing to do with your data (perhaps just a one-up from the previous record).

Then for your entity description table create one that has its own primary key (don't use composite keys unless you really have to). Put a column in that will hold the entity's primary key. Then add a column for the ISO language code, the title, and description. You can create a reference table with language codes and put a foriegn key constraint on the respecitive column in the description table to make sure you don't get stuff in that column that you're not supposed to. If you need to make sure that entity/ISO codes pairs are unique you can set up a unique constraint on those two columns.

Then just map the entity to description table as a one-to-many (and description to entity as a many-to-one if you need it).

_________________
- Chad


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 11, 2004 5:06 am 
Newbie

Joined: Wed Nov 10, 2004 12:27 pm
Posts: 10
Location: Düsseldorf, Germany
You got my problem quite right.
The idea of adding a dedicated primary-key column to the description table sounds quite nice and I think it'll help getting me further with my OR-mapping.
My gread advantage is, that I can setup the DB according to my needs. However, I'd like to specifiy the mapping with XDoclet within the Java layer for having all datamodel issues in one central place of the application for providing more flexibility and better maintainability.
From the DB point of view I would model the ER as follows:
I have an entity table and a description table.
The description table has a composite-key consisting of the corresponding entity-id and the iso-language code (or, as I got from your post, a dedicated primary key). So, there may be more than one row in the description table belonging to an entity.

On the java side, I have an entity and a description class. The description class contains two Maps (in detail: HashMaps), one for title and one for description and a set containing the iso language codes a description/title exists for. Now, my question here is, is it possible to map my java description class to the description table with XDoclet (how can I tell XDoclet to create a unique constraint on two columns)? Or do I have to write the hibernate xml mapping on my own instead? Is it possible, to map multiple rows of one table to one java object? The other possibility would be, of course, that I setup the tables in a different way, but I think it would be convenient to create the tables as described above.

Chris


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

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.