Hello,
This is my case: In my company we are rebuilding our system and
I have 2 different DB tables, one is a legacy table I want to support and the other is a new table.
Both tables represent the same entity, but with some columns renamed/ added/ removed.
My solution was to create one abstract class (lets call it Item) which I annotated with the following:
@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Item @Id @Column(name = "id") private Long id; @Column(name = "name") private String name;
I then created two more classes extending this abstract class:
@Entity @Table(schema = "schema1", name = "TABLE_V1") @AttributeOverrides( { @AttributeOverride(name = "id", column = @Column(name = "id_v1")), @AttributeOverride(name = "name", column = @Column(name = "name_v1")) }) public class ItemV1 extends Item
and -
@Entity @Table(schema = "schema2", name = "TABLE_V2") public class ItemV2 extends Item
Item defines the common attributes from both tables (id and name).
ItemV2 is meant for the new DB table and is currently not having properties which are not already defined in the abstract Item.
ItemV1 should support the legacy table. In the future I expect not to use it anymore, with no affection over my design.
My problem is I can't override the column names using the @AttributeOverrides annotation in ItemV1.
Can anyone tell me how to overcome this obstacle or think of a better way to implement this?
_________________ Regards,
Uri Bar
|