Good morning, I am having an issue with using an @DiscriminatorColumn
as part of a composite primary key.
I have used the @DiscriminatorOptions(insert=false)
to try and prevent the duplicate insertions when the query is parsed but I still seem to get the duplicated inserted column.
@Embeddable
public class MyCompositeID implements Serializable {
@Column(name = "parent_id")
private Integer parent;
@Column(name = "country_code")
private String countryCode;
@Enumerated(EnumType.STRING)
@Column(name = "payment_method",updatable = false,insertable = false)
private PaymentMethod paymentMethod;
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "payment_method")
@DiscriminatorOptions(insert = false)
@Table(name = "parent_payment_params")
public abstract class PaymentParam {
@EmbeddedId
private MyCompositeId id = new MyCompositeId();
public void setCountryCode(String cc){
this.id.setCountryCode(cc);
}
@JoinColumn(name = "parent_id")
@MapsId("parent")
@ManyToOne(fetch = FetchType.LAZY)
private Parent parent;
}
The basic idea is a parent has PaymentParams
that are country and method specific.
So a Parent has many of these PaymentParams
that have a composite ID of the countrycode and the payment method.
The inheritance is on the payment method, so there are say:
CreditCardPaymentParams
and WebFormPaymentParams
etc. extending this base PaymentParams
org.hibernate.exception.SQLGrammarException: could not prepare statement [Duplicate column name "PAYMENT_METHOD"; SQL statement:
insert into parent_payment_params (payment_method,country_code,parent_id,payment_method) values ('CC',?,?,?) [42121-224]] [insert into parent_payment_params (payment_method,country_code,parent_id,payment_method) values ('CC',?,?,?)]
Thank you for any help! I am not sure if I am missing something.