-->
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.  [ 5 posts ] 
Author Message
 Post subject: creation timestamp on JoinTable
PostPosted: Fri Aug 31, 2007 4:59 pm 
Newbie

Joined: Fri Aug 31, 2007 4:35 pm
Posts: 4
I have a join table with a name like "baker_buns" generated from an @ManyToMany mapping which has two columns: bakers_id and buns_id.

How can I get hibernate to also add a timestamp column to this table which will be set to current time whenever a row is added to the table?

The annotated code looks something like this:

Code:
@Entity
public class Baker {
    private Set<Bun> buns;
    // ...
    @ManyToMany
    public Set<Bun> getBuns() {
        return buns;
    }   
    public void setBuns(Set<Bun> buns) {
        this.buns = buns;
    }   
}   

@Entity
public class Bun {
    private Set<Baker> bakers;
    // ...
    @ManyToMany( mappedBy="buns" )
    public Set<Baker> getBakers() {
        return bakers;
    }   
    public void setBakers(Set<Baker> bakers) {
        this.bakers = bakers;
    }   



Top
 Profile  
 
 Post subject: Re: creation timestamp on JoinTable
PostPosted: Fri Aug 31, 2007 6:31 pm 
Beginner
Beginner

Joined: Tue Oct 10, 2006 3:23 am
Posts: 33
I think the easiest is to use a collectionofcomponents. there is that very same example you want on p309 of the hib bible (java persistence with hibernate)

* rate if this helps *


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 9:52 am 
Newbie

Joined: Fri Aug 31, 2007 4:35 pm
Posts: 4
So basicly a change from:

Code:
   
  Baker { Set<Bun> buns; }
  Bun   { Set<Baker> baker; }


to

Code:
   
  Baker { Set<BakersBuns> bakersBuns; }
  Bun { Set<BakersBuns> bakersBuns; }
  BakersBuns { Baker baker; Bun bun; Date bakedOn; }


right?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 3:18 pm 
Beginner
Beginner

Joined: Tue Oct 10, 2006 3:23 am
Posts: 33
Yup, something like that using @CollectionOfElements and @Temporal on BakerBuns.bakedOn

* RATE IF THIS HELPS *


brian_of_fortent wrote:
So basicly a change from:

Code:
   
  Baker { Set<Bun> buns; }
  Bun   { Set<Baker> baker; }


to

Code:
   
  Baker { Set<BakersBuns> bakersBuns; }
  Bun { Set<BakersBuns> bakersBuns; }
  BakersBuns { Baker baker; Bun bun; Date bakedOn; }


right?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 05, 2007 2:27 pm 
Newbie

Joined: Fri Aug 31, 2007 4:35 pm
Posts: 4
Excellent! Thanks a lot, dude.

I think I may end up using something more like:

http://www.hibernate.org/hib_docs/entit ... eners.html

cuz it turns out I need more audit information than just a single timestamp will handle


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