• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA many-to-many with extra attribute

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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!

Jair
 
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic