I am having a problem trying to use an Entity as a part of composite PK.
I am using separate class for @Embeddable PK and my example is similar to Footballer – FootballerPk example.
I am trying to have Country as a part of PK.
I am getting:
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [com.alarm.indicators.Indicator]
Hibernate trace is saying:
Hibernate: insert into TBL_INDICATOR (name, code, country) values (?, ?, ?)
Here is my java code:
@Entity
public class Country implements Serializable{
private String name;
@Id
private String countryCodeIso2lt;
//… getters and setters
@Entity
@Table(name="TBL_INDICATOR")
@IdClass(IndicatorPk.class)
public class Indicator implements Serializable {
@Id
private String code;
private String name;
@Id
@ManyToOne
private Country country;
//… getters and setters
@Embeddable
public class IndicatorPk implements Serializable{
private String code;
private Country country;
//… getters and setters
What am I doing wrong?
Any help appreciated…
|