Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One-to-oneish JPA mapping/query

 
Nicklas Karlsson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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 ]
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic