-->
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: Mapping Relationship with Recorded Timestamp
PostPosted: Sun Sep 12, 2010 1:18 am 
Newbie

Joined: Sun Sep 12, 2010 1:06 am
Posts: 1
Hey everyone,

I've spent a few hours pondering how to approach this mapping in Hibernate, it's very possible there's an easy solution that I'm missing but I'm stumped currently, and would really appreciate any insight.

Essentially, what I'm trying to do is keep a recording of the time a join occured between two objects, here's an example.

A USER instance can subscribe to many THREAD instances, and vice versa, thus a many-to-many relationship. In addition, I wish to record the time that the subscription was made, so I can keep track of the most recent subscriptions of the user. In a database, typically this would be mapped as follows:

USER [user_id]
THREAD [thread_id]
USER_THREAD [user_id, thread_id, subscription_time]

I'm trying to figure out how to model this on the Java side. Typically, I would create a USER object that returns a list of THREAD objects, but have no idea how I'd track the subscription time value without an additional wrapper class to handle the relationship (which I'd really like to avoid). I know lists can have an order value, but I would prefer to record the time instead of the order per say, as it's a more accurate data model and would make it easier for some of our management-based tasks.

Thanks so much for any help!
Shawn


Top
 Profile  
 
 Post subject: Re: Mapping Relationship with Recorded Timestamp
PostPosted: Sun Sep 12, 2010 7:44 am 
Newbie

Joined: Tue Aug 24, 2010 7:04 am
Posts: 14
Hi, it is not possible without createing an own entity for the releationship. See the following example: http://www.java2s.com/Code/Java/JPA/Set ... undKey.htm
The @ID annotations in the class ProjectAssignment must be on the relationship not on the int id values as in the example.

Kind regards
Michael


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.