-->
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: How to map a list in an auxiliary/joined table?
PostPosted: Thu Mar 25, 2010 8:00 am 
Newbie

Joined: Tue Dec 08, 2009 8:03 am
Posts: 6
Hi. I'm trying to develop a simple 'Not a hello world' app using Hibernate from an existing database and I can't figure out how to manage o/r mapping.

So I have two classes Task and Tag which resemble basic id and title fields. In addition Task has a List<Tag> tags field. Here I need to map tags field in an auxiliary table. So DB should have three table: TAG, TASK, TASK_TAG. Like this:

Code:
TASK
task_id<<PK>>
task_title

TAG
tag_id<<PK>>
tag_title

TASK_TAG
task_id  <<FK>><<PK>>
tag_id <<FK>><<UNIQUE>>

Can any one help me with that issue? I would appreciate any help. Thanks in advance.

_________________
We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths.


Top
 Profile  
 
 Post subject: Re: How to map a list in an auxiliary/joined table?
PostPosted: Thu Mar 25, 2010 2:18 pm 
Newbie

Joined: Tue Dec 08, 2009 8:03 am
Posts: 6
So I figured out that the missing part was as follows:
Code:
<!-- Tags mapping needed -->
        <list name="tags" table="task_tag">
         <key column="task_id"/>
         <list-index base="0"/>
         <many-to-many column="tag_id" class="com.raccoon.core.persistence.model.Tag"/>
      </list>

But since list persists element's positions I get next column structure of table TASK_TAG:

realm_id
tag_id
idx

Can any one tell me how to get rid of idx column? Maybe by using another data type (java) like collection?

_________________
We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths.


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.