-->
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.  [ 1 post ] 
Author Message
 Post subject: JPA - Join Tables with Effective Dates
PostPosted: Mon Dec 15, 2008 12:24 pm 
Newbie

Joined: Mon Dec 15, 2008 12:08 pm
Posts: 1
Hello everyone, I have been fighting with defining a class with effective dates as part of the join table and just cannot figure out how to make it work. I have search all over the net for clues, but have yet to find anything such like this. If anyone has experience with this, I would really love to hear your thoughts.

I have the following tables:

PRODUCT
PRODUCTID - PK
... more

CATEGORY
CATEGORYID - PK
... more

CATEGORY_MEMBER
PRODUCTID - PK
CATEGORYID - PK
FROM_DATE - PK
THRU_DATE
SEQUENCE_NUM

This way the same product can be a member of the category at different times. I just for the life of me cannot figure out how to annotate my class (Product for example) with the ManyToMany relationship to support this join table.

I have tried creating a new entity class ProductCategoryMember and defined the fields there.

In my product class I defined the join as:
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "CATEGORY_MEMBER", joinColumns = {@JoinColumn(name = "PRODUCTID")},
inverseJoinColumns = {@JoinColumn(name = "CATEGORYID")})

When the table is created however, the FROM_DATE is not part of the PK. I tried adding FROM_DATE to the inverseJoinColumns as well, but that just threw an exception.

Also, how do I tell the relation to order the results by the join table's sequence_num?

Any help would be greatly appreciated. Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.