I have a Price object consisting of two MonetaryValues, where one MonetaryValue consists of a sum and a currency.
If I configure OR-mapping XML-way, I can do it
<component name="baseAmount" lazy="false" class="MonetartyValue"> <property name="amount" column="baseAmount" precision="20" scale="2" not-null="true" /> </component> <component name="originalAmount" lazy="false" class="MonetaryValue"> <property name="amount" column="originalAmount" precision="20" scale="2" not-null="true" /> <property name="currency" column="originalCurrency" not-null="true" /> </component>
i.e. choose not to save the baseCurrency element (since it is implicit and always the same).
Can this be achieved in the form of an annotation configuration?
If I just do this and ignore the baseCurrency attribute, it will be saved in any case with the default name.
@Embedded @AttributeOverrides ( { @AttributeOverride(name="amount", column= @Column(name="baseAmount")) } ) private MonetaryValue baseAmount; @Embedded @AttributeOverrides ( { @AttributeOverride(name="amount", column= @Column(name="originalAmount")), @AttributeOverride(name="currency", column= @Column(name="originalCurrency")) } ) private MonetaryValue originalAmount;
It is also impossible to make the currency of the MonetaryValue property transitional, since then it will never be saved.
So, is it possible to achieve what the above XML mapping does through annotations?
Just as mtpettyp suggests, I want to save two MonetaryValue files in a table using only three columns. As the autocracy suggests in your comment, you could solve the problem of inheritance. But then again, you can also solve it using a custom .hbm.xml-mapping file instead of using annotations. I am not sure which is more correct, but I am still wondering if it can be solved with either ...