I'm mixing inheritance strategies but am not sure how to do this with annotations. I have a base abstract entity class that contains an id (the PK). All concrete entities extend from this. For each implementation class, I use the AttributeOverride annotation to override the id name for the table. Now since I'm mixing inheritance strategies--using table-per-class-hierarchy with a join table--and hence I'll need to use the SecondaryTable annotation to join at the pk columns. My question is, how do I specify the pkJoinColumns attribute to use the AttributeOverride of the id? An example of this is shown below:
Code:
@MappedSuperclass
public abstract class AbstractHibernateEntity implements Serializable {
protected Long id;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
@Entity
@Table(name = "Item")
@AttributeOverride(
name = "id",
column = @Column(name = "item_id")
)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name = "item_type",
discriminatorType = DiscriminatorType.STRING
)
public abstract class AbstractItem extends AbstractHibernateEntity {
protected String name;
protected BigDecimal value;
public abstract String shippingLabel();
}
@Entity
@DiscriminatorValue("Returned_Item")
@AttributeOverride(
name = "id",
column = @Column(name = "returned_item_id")
)
@SecondaryTable(
name = "Returned_Item"
pkJoinColumns = @PrimaryKeyJoinColumn(name = "returned_item_id")
)
public abstract class AbstractReturnedItem extends AbstractItem {
}
@Entity
@DiscriminatorColumn("Damaged_Item")
public class DamagedItem extends AbstractReturnedItem {
....
}
The above annotations do not work. I'm thinking its because the SecondaryTable annotation is incorrect for the AbstractReturnedItem class. Also, now that I'm looking at the bigger picture, the AbstractReturnedItem should just be another @MappedSuperclass. Not sure what's right anymore. Any help would be appreciated.
-nefi