-->
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.  [ 6 posts ] 
Author Message
 Post subject: Mapping multiple sets to one table
PostPosted: Wed Dec 01, 2004 8:01 am 
Newbie

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

I wonder if the following is possible within hibernate. Within my Object model I have a class 'EntityDescription' which stores the title and a descriptive text for a specified language for a corresponding entity. The title resp. the description are stored within a HashMap each, with the language as key.
For the relational model it seems quite convenient to me, that the sets of 'EntityDescription' are mapped to one table:

create table DESCRIPTIONS (
ENTITY_ID bigint not null,
DESCRIPTION varchar(255),
ISO_LANG_CODE varchar(2) not null,
TITLE varchar(255),
primary key (ENTITY_ID, ISO_LANG_CODE)
);

The standard SQL-operation for a new title or description is an INSERT-statement which leads to a 'Duplicate key or integrity constraint violation message'. The statement should be an update, if there exists already a row with the composite keys.
Is it possible to tell hibernate, that there are multiple sets mapped to one table? Or to I have to cope with redundancy and let hibernate manage the sets by one table for each set with exact the same key-values?

Hibernate version: 2.1.7c

Mapping documents:
Code:
<component
    name="entityDescription"
    class="com.raytion.catalog.model.EntityDescription"
>

        <map
            name="descriptions"
            table="DESCRIPTIONS"
            lazy="false"
            sort="unsorted"
            inverse="false"
            cascade="all"
        >

              <key column="ENTITY_ID"/>
              <index
                  column="ISO_LANG_CODE"
                  type="string"
                  length="2"
              />
              <element
                  column="DESCRIPTION"
                  type="string"
                  not-null="false"
                  unique="false"
              />
        </map>

        <map
            name="titles"
            table="DESCRIPTIONS"
            lazy="false"
            sort="unsorted"
            inverse="false"
            cascade="all"
        >

              <key column="ENTITY_ID"/>
              <index
                  column="ISO_LANG_CODE"
                  type="string"
                  length="2"
              />
              <element
                  column="TITLE"
                  type="string"
                  not-null="false"
                  unique="false"
              />
        </map>
</component>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Don't know if the following is usable for you - but look at http://blog.hibernate.org/cgi-bin/blosx ... 06/23#i18n which is one way to handle i18n with hibernate.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 9:19 am 
Newbie

Joined: Wed Nov 10, 2004 12:27 pm
Posts: 10
Location: Düsseldorf, Germany
The suggested pattern by Gavin looks quite nice, thanks for the link.

Am I right then, if I conclude from your answer that it isn't possible with Hibernate to map multiple sets to one table?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 9:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - well you are "splitting" up what is actually an entity/row into two distinct items.

And it would be quite inefficient do handle this - i think.

But take a look at http://www.gloegl.de/blog/archives/hibe ... e-columns/ which touches on a similar situation.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 9:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, mapping a single private map and then creating two map wrappers around it would be a solution I think.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 10:02 am 
Newbie

Joined: Wed Nov 10, 2004 12:27 pm
Posts: 10
Location: Düsseldorf, Germany
Yes, I understand that it's not possible for hibernate to split rows for different instances. I'll think about the wrapping approach, sounds quite nice and feasible.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.