Skip to main content

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

The solution for this in JPA is to use the @AttributeOverrides.

The prefix sounds like it could be a useful feature; perhaps log an enhancement request for it.  It is not part of JPA, so would need to be its own extension annotation, i.e. @EmbeddedPrefix("N_").


-----Original Message-----
From: Mark Struberg [mailto:struberg@xxxxxxxx]
Sent: Sunday, November 09, 2008 5:37 PM
To: eclipselink-dev@xxxxxxxxxxx
Subject: [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



_______________________________________________
eclipselink-dev mailing list
eclipselink-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-dev


Back to the top