Jpa subclass mapping
        Posted  
        
            by Roy Chan
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Roy Chan
        
        
        
        Published on 2010-06-02T21:07:05Z
        Indexed on 
            2010/06/02
            23:44 UTC
        
        
        Read the original article
        Hit count: 336
        
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?
© Stack Overflow or respective owner