Issue
I have the following set of classes
@Embeddable
public class SharedClass {
...
private String legacyField;
...
}
@Entity
public class LongStandingEntity {
...
private SharedClass sharedClass;
...
}
Where legacyfield
stores some obsolete data in older objects but is not collected for new ones. However I do need to able to continue to access the old data.
I'm creating a new entity that also makes use of SharedClass
@Entity
public class NewEntity {
...
private SharedClass sharedClass;
...
}
It doesn't need legacyField
and I'd like to avoid having to add a column in the database for it whilst keeping the mapping working for LongStandingEntity
.
Is this possible with JPA annotations?
Solution
I don't recall a particular annotation that can help you with that. Still I'd rather take a design approach with this situation. If you have field that belongs only to a certain class separate them in another embedabble class that's associated only with the older data.
Seems like a cleaner approach to me, just to keep entities clearly differenciated.
Answered By - Fritz
Answer Checked By - Terry (JavaFixing Volunteer)