Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering your thoughts on the best way to implement a SQL ManyToMany relationship in Java using annotations - in this case eBeans - where there is extra data associated with the join.

I have created a db diagram to help explain:


Using @ManyToMany on the organisation and users classes would create the join table but without the extra Job Title.

Is the best way to implement this to create the Org_has_users class and use @OneToMany and @ManyToOne annotations? Would cascade on save ensure that I can access the full join relationships from both the Users and Organisations classes?

I hope this is enough to get started. I am more interested in how you would implement this.

Thanks! Anthony

share|improve this question
This maybe relevant:… – NoChance Aug 2 '12 at 10:12
up vote 2 down vote accepted

The easiest way to implement this is to place an entity between the two Entities, which holds the additional values.

There are downsides to this approach: You need to reference the table from one or two sides, what makes it harder to maintain the correct values and adds in the worst case additional linking tables - all values must be removed in both sides of the collection and all JoinTables must be correct.

I don't know exactly about eBeans, but there are ways to do this, see here (especially the comment to the answer):

share|improve this answer
Hi Volker,Thanks for the link. I agree it seems the easier way is to place an entity between the two. It looks like it may also be better to not Cascade and save manually in order to ensure the integrity of the joins. I shall have a play! Thanks again – afxdesign Aug 2 '12 at 15:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.