• 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

One-to-oneish JPA mapping/query

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

I'm taking this here since e.g the Hibernate forums aren't that friendly to noobs with mapping probs ;-)

Summary: how to do a JPA one-to-one mapping (or query) when the relation needs "outside" data.

Say we have Product:


and we have Customer:


but we want different prices for different customers so we have Price


(Bill shops plenty of moose heads and booze so he gets a discount)

How could I map (or query) the one-to-one Product -> Price when it only becomes one-to-one when you specify the customer. In the above case the both products have to prices until you specify what customer you have attached, right? I would like to do a "from Product" when Bill Redneck is logged in so I get a list of Product(s) populated with the Price(s) for Bill Redneck. How should this customer info be "queried in".

Thanks in advance,
-Nik

[ November 20, 2007: Message edited by: Nicklas Karlsson ]
[ November 20, 2007: Message edited by: Nicklas Karlsson ]
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nicklas,

welcome to JavaRanch.

this question is more about data/entity modeling than mapping. The typical approach is to define a many-to-many relationship between Customer and Product, implement it with a join table CustomerProduct (an intermediate entity which has many-to-one relationships with Customer and Product), which has a Price attribute. Not sure where this is best described; you may start here, for example.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic