-->
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.  [ 2 posts ] 
Author Message
 Post subject: Map collection in several tables to single many-end table
PostPosted: Sun Oct 12, 2003 4:47 pm 
Newbie

Joined: Sun Oct 12, 2003 4:21 pm
Posts: 16
Location: Stockholm, Sweden
Hi, I have a mapping problem.
I have 20 lookup tables that should hold 'name' and 'description'. The description must be multi-language so I want to put the description column in another table with a one-many association (or a Map). But I dont want 20 description tables, I'd like to have only one description table that holds description for all 20 lookup tables.

I have tried two different approaches without success. First a one-many association with a Set in each lookup table class.

LOOKUPTABLE_1 (ID = primary key, NAME = string(10))
LOOKUPTABLE_2
LOOKUPTABLE_3
......
LOOKUPTABLE_20

LOOKUPDESCRIPTION (ID = primary key, OWNER = foreign key, LANG = string(5), DESC = string(100)

But it fails on insert of LOOKUPDESCRIPTION. The OWNER column is NULL. I have tried to set the OWNER column myself but I dont know where to set it.

The second try was using a Map with the LANG column as index column. But that makes hibernate create a constraint between LOOKUPTABLE_1 and LOOKUPDESCRIPTION, not for the other lookup tables. I dont want it to create a constraint to any table.

Is it possible to do this kind of mapping, or do I have to create 20 description tables?
I have read the collection chapter in the manual but I'm still not sure.

/Goran


Top
 Profile  
 
 Post subject: Re: Map collection in several tables to single many-end tabl
PostPosted: Mon Oct 13, 2003 2:12 pm 
Newbie

Joined: Sun Oct 12, 2003 4:21 pm
Posts: 16
Location: Stockholm, Sweden
goeh wrote:
But it fails on insert of LOOKUPDESCRIPTION. The OWNER column is NULL. I have tried to set the OWNER column myself but I dont know where to set it.

I solved it!

This is how the mapping looks like on all 20 lookup tables:
Code:
        <set
            name="descriptions"
            table="LOOKUPDESCRIPTION"
            lazy="false"
            inverse="true"
            cascade="all"
        >

              <key
                  column="OWNER"
              />

              <one-to-many
                  class="foo.bar.LookupDescription"
              />
        </set>

But I still have to set OWNER myself. I do that with onSave(Session) in all parent classes (abstract super class).
At first I could not get this to work, but I had mixed up the return values from the Lifecycle methods. I returned true (sounded reasonable). But reading the manual word by word I found out that you should return false from those methods if you dont want to veto the operation.
Now it works as I want it to work, great!

/Goran


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