Feb 29th, 2012, 03:16 PM
OpenJPA: @Embedded vs @EmbeddedCollection
I am trying to decide which annotation to use. Can you offer your opinion?
One of my entities (let's call it Balance) contains several embedded objects of the same type (let's call it Amount). Right now there are 7 of these objects inside the Balance entity. I override the column names of Amount to be able to store all of this data in the Balance table in the database.
The Amount objects for one Balances are often treated as a group, so, conceptually, they could be a collection. In fact, I really want to use @EmbeddedCollection annotation and map these objects as a Map<AmountType, Amount> inside the Balance, where AmountType would be an enumeration with possible amount types.
The problem is, if I do that - I will not be able to store all of the data in the same table (correct?). I would need to have a separate tables for my Balance and for Amounts linked to the Balances. This means JOINs when working with the data... What would you do here? Would you map these objects as an @EmbeddedCollection?