我有2个Hibernate实体实体: LanguageToLocaleJpaImpl
,它与2个不同的 LocaleJpaImpl
实例有2个关联。
LanguageToLocaleJpaImpl
具有以下外键:
当我启动Tomcat服务器时,我收到此异常:
引用 LanguageToLocaleJpaImpl
的 LocaleJpaImpl
中的ReferencedColumnNames未映射到单个属性
我真的不知道是什么原因引起的。 你能帮忙吗?
这是 LanguageToLocaleJpaImpl
类:
@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...
}
这是 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...
}
答案 0 :(得分:1)
据我所知,Hibernate已经识别出相关LocaleJpa的主键,因此认为有两个外键定义了这两个类之间的关系。 我解决了删除@Id注释的问题,而是添加了
@AttributeOverride(name="id", column=@Column(name="LOCALE_ID"))
在课堂签名之前。