我有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...
}
最佳答案
据我了解,Hibernate已经识别了关联的LocaleJpa的主键,因此认为有2个外键定义了两个类之间的关系。
我解决了删除@Id注释的问题,而是添加了
@AttributeOverride(name="id", column=@Column(name="LOCALE_ID"))
上课前签名。