• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JPA many-to-many with extra attribute

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have this tables:

Table: users

id integer
name varchar

Table: user_contacts

user_id integer
contact_id integer
active boolean

This is a self many-to-many relationship (user_id and contact_id is an user) with an extra attribute.

How I can map this with JPA?

With hibernate I do this:

Thank you!

Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Hibernate you were in-lining a composite object and defining a 1-m relationship to te contact object, with a m-1 back from the contact to the user. Similarly, in JPA you would define a contact entity and a 1-m relationship from user to contact and m-1 from contact to user. The only difference is that in JPA contact is a 1st class entity instead of a second class composite.
rubbery bacon. rubbery tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic