I have same-named field (int phone;) both in my entity class and in the embedded class. As per JPA Specification I shall use @AttributeOverrides in my entity over the embedded field.
The logic behind that: fields of embedded class are saved to the same database table as fields of entity class itself (loosely speaking adding one embedded filed to entity class looks like just adding all fields of the embeddable class to that entity), and thus we have two fields with the same default name for a respective column of the table used to store the entity in the database.
But what if I specify @Column(name="alternative_phone_name") either on the filed of Embeddable class, or on the filed of the Entity class - in such case there is no conflict and no @AttributeOverrides is necessary? Right? This is my question.
Secondly, what happens if I specify @Column(name="alternative_phone_name") on the filed of Embeddable class and then also redefine it with @AttributeOverrides over the embedded field inside the entity class? Is it an error and what would the database column name be in that case?
@Embeddable
class MyEmbeddable {
@Column(name="my_embed_phone")
int phone;
}
class MyEntity {
int phone;
// 1) do I need
// @AttributeOverrides({
// @AttributeOverride(name="phone", column="sth_different_than_phone")
// })
// 2) If I don't need it, would specifying it is error?
// Which overrides - this @AttributeOverrides or MyEmbeddable's @Column(name=...
@Embedded
MyEmbeddable embeddedFld;
}