Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-dev] what do you think of the following @Embedded extension

Hi!

I hope my post isn't getting too confusing, so I'd like to start with a question:

I came across a problem while embedding the same @Embeddable class 2 times in an @Entity:

Let's assume I have a Price which always looks the same:
   @Embeddable
   public class Price {
   	public BigDecimal amount;
   	public String currency;
   }
   
and I'd like to use this Price for storing the net price and the price including all the taxes:
   @Entity
   public class Purchase {
   	@Embedded
   	private Price netPrice;
   
   	@Embedded
   	private Price grossPrice;
   }

You know, we are used to fumble around with @AttributeOverrides, but to be honest, this is not satisfyingly (this did e.g. work really well in JDO), since it lacks a proper handling for nested embeddings, etc.

So, maybe there is already a solution for this problem, and I simply didn't find it. I know there has been some discussions about nested embedded fields, but I didn't find my problem covered in the JPA-2.0 spec.
If it's not fixed already, I would be glad if JPA 2.0 would introduce a way to manually set a prefix for all fields of the embedded class, which would look something like the following example:

   @Entity
   public class Purchase {
   	@Embedded(prefix="N_") 
   	private Price netPrice;
   
   	@Embedded(prefix="G_") 
   	private Price grossPrice;
   }

Which would generate the database columns
N_AMOUNT
N_CURRENCY
G_AMOUNT
G_CURRENCY

For nested embeddings, the prefixes would simply stack.

What do you think about this?
Or is there a better solution, and I was only too blind to see it?

txs in advance and LieGrue,
strub





Back to the top