I have two @Entity A and B, and I have an @Embeddadble Address as follows:
Code:
@Embeddable
public class Address {
private String line1;
private String line2;
...
}
Code:
@Entity
public class A {
@Id private long id;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="line1", column=@Column(name="TABLE_A_LINE1")),
@AttributeOverride(name="line2", column=@Column(name="TABLE_A_LINE2"))
})
private Address address;
}
Code:
@Entity
public class B {
@Id private long id;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="line1", column=@Column(name="TABLE_B_LINE1"))
// don't want line2 in B
})
private Address address;
}
The table for @Entity B has no TABLE_B_LINE2 column, but I still want to embed Address in B because it makes sense in my model. The mapping above doesn't work for B because the SQLs generated by Hibernate always reference line2 column.
If I put @Transient in Address.line2, it works for @Entity B, but now @Entity A loses its capacity to query, insert and update line2.
Do you think it's possible to selectively ignore some attributes of an @Embeddable?