I have 2 Hibernate entities Entities: LanguageToLocaleJpaImpl that has 2 associations with 2 different instance of LocaleJpaImpl.
LanguageToLocaleJpaImpl has the following Foreign Keys:

when I launch the Tomcat server I receive this Exception:
ReferencedColumnNames in LanguageToLocaleJpaImpl referencing LocaleJpaImpl are not mapped to a single property
I have really no idea what can cause that. Can you help please?
This is the LanguageToLocaleJpaImpl class:
@Entity
@Table(name = "LANGUAGE_TO_LOCALE")
@XmlRootElement
public class LanguageToLocaleJpaImpl extends BaseEntityJpaSupport implements Serializable, LanguageToLocale {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@GeneratedValue( strategy = GenerationType.AUTO)
@Column(name = "LANGUAGE_TO_LOCALE_ID")
private Integer languageToLocaleId;
@Basic(optional = false)
@NotNull
@Column(name = "ACTIVE_FLAG")
private boolean activeFlag;
@Basic(optional = false)
@NotNull
@Column(name = "DEFAULT_FLAG")
private boolean defaultFlag;
@Column(name = "CREATED_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date createdDate;
@Column(name = "UPDATED_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedDate;
@JoinColumn(name = "LOCALE_ID", referencedColumnName = "LOCALE_ID")
@ManyToOne(optional = false)
private LocaleJpaImpl country;
@JoinColumn(name = "LANGUAGE_ID", referencedColumnName = "LOCALE_ID")
@ManyToOne(optional = false)
private LocaleJpaImpl language;
public LanguageToLocaleJpaImpl() {
}
// Getters e Setters, Hashcode, Equals, toString...
}
This is LocaleJpaImpl:
@Entity
@Table(name = "LOCALE")
@XmlRootElement
public class LocaleJpaImpl extends BaseEntityJpaSupport implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "LOCALE_ID")
private int localeId;
@Basic(optional = false)
@NotNull
@Column(name = "CREATED_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date createdDate;
@Size(max = 2)
@Column(name = "LANGUAGE_CODE")
private String languageCode;
@Size(max = 2)
@Column(name = "COUNTRY_CODE")
private String countryCode;
@Size(max = 10)
@Column(name = "VARIANT_CODE")
private String variantCode;
@Size(max = 100)
@Column(name = "FLAG_ICON_URL")
private String flagIconUrl;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "language")
private List<LanguageToLocaleJpaImpl> languageList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "country")
private List<LanguageToLocaleJpaImpl> countryList;
public LocaleJpaImpl() {
}
@XmlTransient
public List<LanguageToLocaleJpaImpl> getLlanguageList() {
return languageList;
}
public void setlanguageListList(List<LanguageToLocaleJpaImpl> languageList) {
this.languageList = languageList;
}
@XmlTransient
public List<LanguageToLocaleJpaImpl> getCountryList() {
return countryList;
}
public void setCountryList(List<LanguageToLocaleJpaImpl> countryList) {
this.countryList = countryList;
}
// Getters e Setters, Hashcode, Equals, toString...
}
As I could understand Hibernate already recognise the primary key of the associated LocaleJpa and consequentely thinks that there are 2 foreign keys defining the relation between the two classes. I solved the issue removing the @Id annotation and instead I added
@AttributeOverride(name="id", column=@Column(name="LOCALE_ID"))
before the class signature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With