-->
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: Complex Hibernate xdoclet mapping
PostPosted: Mon Mar 07, 2005 9:25 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 7:53 am
Posts: 32
Location: Madrid - Spain
Hi mates, I've been searching throughout the forum and I couldn't solve I problem I have. So, I decided to post it and wait for someone to help me.

Well, I have three tables: users, subscriptions and thirdparties. The first one has a UserID primary key. The second one has UserID and ThirdPartyID composite primary keys wich are foreign keys if seen individually. Finally, the third table has a ThirdPartyID primary key

As you can see, the relationship is so that given a user I have many subscriptions. Similarly, given a third party I have many subscriptions. Then, I would like to map for an user a set with all subscriptions he/she is registered in. Can I do that by using xdoclet? If not, can I do it with any other tool? If still not, how can I do it manually?

Thans to all for your huge help... ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 07, 2005 9:55 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Yes - this is a simple many-to-many mapping and is handled by x-doclet.

e.g.
Code:
    /*
     * @hibernate.set
     *      cascade = "all"
     *      lazy = "true"
     *      table = "relationship_table"
     * 
     * @hibernate.collection-key
     *      column = "fk_to_this_object"
     *
     * @hibernate.collection-many-to-many
     *      class = "related object"
     *      column = "primary_key_of _related_object"
     */


You will have a similar mapping on the other side. Only one of the sides should be marked as inverse.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 07, 2005 11:10 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 7:53 am
Posts: 32
Location: Madrid - Spain
Thanks drj for your quick reply. However, I'm not sure this is a many-to-many relationship as you suggested, but a one-to-many relationship. I think Users is at the one side and Subscription is at the many side.

Additionally, I couldn't map this (one-to-many) relationship as a normal one, because I have a SubscriptionId class which encapsulates the both IDs of Subscription. Hence, the complexity I don't know how to face with.

So to sum up, I have Users class which needs a java.util.Set with subscriptions. Subscription class has an SubscriptionID type id field which represents the ID of every subscription (UserID + ThirdPartyID). Finally, I have ThirdParty class which should (not compulsory) have another set of subsriptions.

Now, that maybe I have exposed my case in further detail, you might help me better. If you need more details, please don't hesitate to letting me know.

Thank you very much! ;)


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.