• Post Reply Bookmark Topic Watch Topic
  • New Topic

Properties of Many-To-Many relationship  RSS feed

 
Jurica Ursic
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need some help setting up relationship properties in EJB3.0. To be more specific consider the following example.

Let us presume I have an entity ExpenseType which holds all kinds of expense types for some expense charge. One of those expense types could be 'Ethernet cable'. An organization could have different price for this ethernet cable when being sold to education institutions in comparison to price when being sold to military.
So we have ExpenseRateCategory entity with two entries (Education and Military) and ExpenseType entity with one entry (Ethernet cable). These have Many-To-Many relationship. I have created entities ExpenseType and ExpenseRateCategory and have managed to establish the relationship between them. The record of the join table holds FKs to ExpenseType.ID and ExpenseRateCategory.ID.

ExpenseRateCategory.ID | ExpenseType.ID

The problem is how to add additional fields to this relationship, namely the price, the value of which depends on both sides of the relationship. That is I want to have record of the join table of the form:

ExpenseRateCategory.ID | ExpenseType.ID | price

How to manipulate those additional fields in the context of EJB3 specification?
[ October 18, 2005: Message edited by: Jurica Ursic ]
 
Mark James
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jurica,

I was wondering if you solved this one. I'm trying to do something very similar, and while I am close to the full solution, I am apparently missing something.

Thanks...

-mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't you normally create a join table and use that as the link between the many to many?

Mark
 
Mark James
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the fact that it's not a junction table, it's an association table - i.e. it has additional business info (fields), including one that is part of the composite pk. (i.e. it's "transactional" and not "transparent")

So (in my case), you have 2 fk's, both of which are part of the primary key, along with one of the "extra" fields. Now, since pk's are unique, don't you end up with two on-to-one relationships due to the unique constraint being applied to the fk's? Is that what you want out of a "many to many, plus data" relationship?

Thx!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!