java Hibernate在实体映射中出现重复列
每当运行单元测试时,我总是面临"Repeated column in mapping for entity: com.ts.user.entity.TutRptLocYearly column: locid (should be mapped with insert="false" update="false")"
问题。
我正在寻求帮助和建议,以解决我的问题,因为我试图解决这个问题,但这个错误不断发生
下面是我的情况
我创建了两个表,TUT_LOCATION(主键:LocID)和TUT_RPT_LOC_Year(主键:LocID+Year,外键:LocID)。通过使用EclipseJPA工具,它为我生成了3个类,tutLocation。java、tutRptLocYearly和tutRptLocYearlyPK
地点。爪哇
@Entity
@Table(name="tut_location")
@NamedQuery(name="TutLocation.findAll", query="SELECT t FROM TutLocation t")
public class TutLocation extends InitEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Integer locid;
private String name;
//bi-directional many-to-one association to TutRptLocYearly
@OneToMany(mappedBy="tutLocation", cascade={CascadeType.ALL})
private List<TutRptLocYearly> tutRptLocYearlies;
public TutLocation() {
}
public Integer getLocid() {
return this.locid;
}
public void setLocid(Integer locid) {
this.locid = locid;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public List<TutRptLocYearly> getTutRptLocYearlies() {
return this.tutRptLocYearlies;
}
public void setTutRptLocYearlies(List<TutRptLocYearly> tutRptLocYearlies) {
this.tutRptLocYearlies = tutRptLocYearlies;
}
public TutRptLocYearly addTutRptLocYearly(TutRptLocYearly tutRptLocYearly) {
getTutRptLocYearlies().add(tutRptLocYearly);
tutRptLocYearly.setTutLocation(this);
return tutRptLocYearly;
}
public TutRptLocYearly removeTutRptLocYearly(TutRptLocYearly tutRptLocYearly) {
getTutRptLocYearlies().remove(tutRptLocYearly);
tutRptLocYearly.setTutLocation(null);
return tutRptLocYearly;
}
}
图坦卡蒙每年一次。爪哇
@Entity
@Table(name="tut_rpt_loc_yearly")
@NamedQuery(name="TutRptLocYearly.findAll", query="SELECT t FROM TutRptLocYearly t")
public class TutRptLocYearly extends InitEntity implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private TutRptLocYearlyPK id;
private Timestamp lastupdate;
private Integer notrans;
//bi-directional many-to-one association to TutLocation
@ManyToOne(cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
@JoinColumn(name="locid")
private TutLocation tutLocation;
public TutRptLocYearly() {
}
public TutRptLocYearlyPK getId() {
return this.id;
}
public void setId(TutRptLocYearlyPK id) {
this.id = id;
}
public Timestamp getLastupdate() {
return this.lastupdate;
}
public void setLastupdate(Timestamp lastupdate) {
this.lastupdate = lastupdate;
}
public Integer getNotrans() {
return this.notrans;
}
public void setNotrans(Integer notrans) {
this.notrans = notrans;
}
public TutLocation getTutLocation() {
return this.tutLocation;
}
public void setTutLocation(TutLocation tutLocation) {
this.tutLocation = tutLocation;
}
}
TutRptLocYearlyPK。爪哇
@Embeddable
public class TutRptLocYearlyPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
@Column(insertable=false, updatable=false)
private Integer locid;
private Integer year;
public TutRptLocYearlyPK() {
}
public Integer getLocid() {
return this.locid;
}
public void setLocid(Integer locid) {
this.locid = locid;
}
public Integer getYear() {
return this.year;
}
public void setYear(Integer year) {
this.year = year;
}
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof TutRptLocYearlyPK)) {
return false;
}
TutRptLocYearlyPK castOther = (TutRptLocYearlyPK)other;
return
this.locid.equals(castOther.locid)
&& this.year.equals(castOther.year);
}
public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + this.locid.hashCode();
hash = hash * prime + this.year.hashCode();
return hash;
}
}
错误消息:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.ts.user.entity.TutRptLocYearly column: locid (should be mapped with insert="false" update="false") at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:830) at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:848) at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:870) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:605) at org.hibernate.mapping.RootClass.validate(RootClass.java:265) at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ... 46 common frames omitted
共 (0) 个答案