Jpa subclass mapping
- by Roy Chan
I am making a POS like system. I wonder how to map subclass using JPA (this is for my DAO). Product class has product details and OrderProduct class has information about the Product and details about the order.
@Entity
@Table(name="products")
public class Product implements Serializable{
@Id
@Column(name="id")
@GeneratedValue(strategy = GenerationType.AUTO
public int getId(){ return id;}
/**
Other get/set methods
*/
}
@Entity
@Table(name="order_products")
public class OrderProduct extends Product{
@Id
@Column(name="id")
@GeneratedValue(strategy = GenerationType.AUTO)
public int getId(){ return id;}
/**
Other get/set methods
*/
}
I got complain about duplicate @Id. But OrderProduct class really need another id than the product one. How should I map this?
DB is something like this
Table products
id int
name varchar(32)
Table order_product
id int
quantity int
productid int fk referencing product table
Would @IdClass or @AttributeOverride help?