Since you are using @IdClass
, the PricePK
class need not be marked with the @Embeddable
annotation. An example is given in http://www.java2s.com/Code/Java/JPA/SetIdClassforCompoundKey.htm
I tried your code removing the @Embeddable
on PricePK
class, and the price table generated in MYSQL database with not null fields.
Following is how you could use @EmbeddedId
to achieve the required result:
(getters and setters omitted)
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Price {
@EmbeddedId
PricePK pricePk;
}
@Embeddable
public class PricePK implements Serializable {
@ManyToOne(optional = false)
private Product product;
@ManyToOne(optional = false)
private Currency currency;
}