-->
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: Adding timestamp to many-to-many relationship tables
PostPosted: Tue Nov 13, 2007 8:57 pm 
Newbie

Joined: Tue Nov 13, 2007 8:49 pm
Posts: 2
Hello Hibernate community,

I have a Hibernate32 question that has exceeded my meager abilities. I have a join table that I use to map Users to Channels in a many-to-many relationship as per the code below. Has worked pretty well for us so far, the join table has just two columns, user_id and channel_id, and hibernate manages that relationship for me whenever we add or remove Channels to the channels collection.

However, now I have a new business requirement that requires that I keep track of WHEN that relationship was established. The most direct way to do this would be to add a created_time column to subscriber_channel_rt and somehow convince Hibernate to manage this column when it adds or removes channels to a user.

However, I'm unclear about how to convince Hibernate to do such a thing, or even if its possible at all. Does anyone have any suggestions about good ways to proceed? So far the best solution I can think of is to bypass hibernate entirely and use MySQL triggers to manage the created_time column, and direct SQL to query on that time, but I'm hoping there might be a more Hibernate-like way...

Thanks so much,
Mike

PS. bonus points for avoiding ugly migrations

Code:
import javax.persistence.*;

@Entity
public class User
{
   // Subscribed channels
    protected List<Channel> channels;

    @ManyToMany
    @JoinTable(name="subscriber_channel_rt",
               joinColumns={@JoinColumn(name="user_id")},
        inverseJoinColumns={@JoinColumn(name="channel_id")})
    @OrderBy(clause="channel1_.name")
    public List<Channel> getChannels()
    {
        return channels;
    }

    public void setChannels(List<Channel> channels)
    {
        this.channels = channels;
    }

}



Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 4:11 pm 
Newbie

Joined: Tue Nov 13, 2007 8:49 pm
Posts: 2
Just thought I'd check in and see if anyone had a suggestion on this one. (In short, how to add a created timestamp to a many-to-many relationship table. See original post below)

Any ideas?

Cheers
Mike


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.