I'm using JPA 1.0 so I am limited in what I can do but I still think it should be possible to do the following however I cant get it working...
Code:
Table CustomerA
a_id
Table ProductB
a_id
b_id
Table ProductC
a_id
c_id
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractProduct {
@Id
@GeneratedValue....
private Long id;
private String name;
@ManyToOne()
JoinColumn(name="a_id")
private CustomerA customerA;
}
Now I want to create a subclass which can over ride the Id or create a composite Key based on the PK of Table A and the key of the derived table...
Code:
@Entity
@Table(name="ProductB")
public class ProductB extends AbstractProduct {
//@AttributeOverride(name="id", column=@Column(name="B_ID") //Can only be used with MappedSuperClass and also Emmbedded Objects
//@Id //cant override the ID Column so that cant go here
//PrimaryKeycolumn join not what i want here
private Long productB_id;
private String productName;
}
@Entity
@Table(name="CustomerA")
public class CustomerA
{
@Id
@GeneratedValue....
@Column(name="a_id")
private Long aId
@OneToMany(mappedBy="customerA", cascade=CascadeType.ALL)
private Set<AbstractProduct> product;
}
So essentially CustomerA can contain many products, but it will always only be of either ProductB or ProductC. How can i override the Id in the subclass as you cant use attributeoverride and Entity, and if you use @Entity you must specify @Id whenever you specify an @Entity. I've read the jpa wiki and it looks rather complicated and ott to achieve this in JPA 1.0, but i'm wondering if I am missing something?