| Summary: | @AttributeOverride does not work with nested embeddables having attributes of the same name | ||||||
|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Sabine Heider <sabine.heider> | ||||
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | adrian.goerler, andreas.paul, eclipselink.orm-inbox, guy.pelletier, konstantin.schwed, michael.f.obrien | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows Vista | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
You can also get around this by using the following model instead:
@Entity
@Table(name="MY_ENTITY")
public class MyEntity {
@Id
private int id;
@Embedded
private Price price;
}
@Embeddable
public class Price {
@Embedded
@AttributeOverrides ({
@AttributeOverride(name="value", column=@Column(name="QTYVALUE")),
@AttributeOverride(name="unitCode", column=@Column(name="QTYUNIT")),
})
Quantity quantity;
@Embedded
@AttributeOverrides ({
@AttributeOverride(name="value", column=@Column(name="AMOUNTVALUE")),
@AttributeOverride(name="currencyCode",
column=@Column(name="AMOUNTCURR"))
})
Amount amount;
}
Since both quantity and amount map to a similar column by default (VALUE),
internally during initialization only one attribute override is captured (the
last one processed) hence the error.
Created attachment 181839 [details]
Proposed changes
Changes have been submitted. Reviewed by: Gordon Yorke New test (testAttributeOverrideToMultipleSameDefaultColumnName) added to AdvancedJPAJunitTest The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
There seems to be a problem with @AttributeOverride when different nested embeddables inside an entity have an attribute of the same name. See the following example: @Entity @Table(name="MY_ENTITY") public class MyEntity { @Id private int id; @Embedded @AttributeOverrides ({ @AttributeOverride(name="quantity.value", column=@Column(name="QTYVALUE")), @AttributeOverride(name="quantity.unitCode", column= @Column(name="QTYUNIT")), @AttributeOverride(name="amount.value", column=@Column(name="AMOUNTVALUE")), @AttributeOverride(name="amount.currencyCode", column= @Column(name="AMOUNTCURR")) }) private Price price; } @Embeddable public class Price { @Embedded Quantity quantity; @Embedded Amount amount; } @Embeddable public class Quantity { int value; String unitCode; } @Embeddable public class Amount { private int value; private String currencyCode; } Note that both Quantity and Amount have an attribute called "value". When I try to persist an instance of MyEntity, I get the following exception: Internal Exception: com.sap.dbtech.jdbc.exceptions.jdbc40.SQLSyntaxErrorException: [-4005] (at 53): Unknown column name:VALUE Error Code: -4005 Call: INSERT INTO MY_ENTITY (ID, AMOUNTCURR, AMOUNTVALUE, VALUE, QTYUNIT) VALUES (?, ?, ?, ?, ?) bind => [1, EUR, 3, 2, kg] When I rename one of the "value" fields, everything works fine.