Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate问题-实体映射中的重复列_Java_Spring_Hibernate_Jpa - Fatal编程技术网

Java Hibernate问题-实体映射中的重复列

Java Hibernate问题-实体映射中的重复列,java,spring,hibernate,jpa,Java,Spring,Hibernate,Jpa,每当运行单元测试时,我总是面对实体映射中的重复列:com.ts.user.entity.tutrptlocyear column:locid(应使用insert=“false”update=“false”)映射“问题。 我正在寻求帮助和建议,以解决我的问题,因为我试图解决这个问题,但这个错误不断发生 下面是我的情况 我创建了两个表,TUT_LOCATION(主键:LocID)和TUT_RPT_LOC_Year(主键:LocID+Year,外键:LocID)。通过使用eclipse JPA工具,它

每当运行单元测试时,我总是面对实体映射中的重复列:com.ts.user.entity.tutrptlocyear column:locid(应使用insert=“false”update=“false”)映射“问题。 我正在寻求帮助和建议,以解决我的问题,因为我试图解决这个问题,但这个错误不断发生

下面是我的情况

我创建了两个表,TUT_LOCATION(主键:LocID)和TUT_RPT_LOC_Year(主键:LocID+Year,外键:LocID)。通过使用eclipse JPA工具,它为我生成了3个类:tutLocation.java、tutRptLocYearly和tutRptLocYearlyPK

TutLocation.java

    @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;
    }
}
TutRptLocYearlyPK.java

@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;
    }
}
错误消息:

原因:org.hibernate.MappingException:映射中重复列 对于实体:com.ts.user.entity.tutrptlocyear列:locid(应该 在中使用insert=“false”update=“false”)进行映射 org.hibernate.mapping.PersistentClass.checkColumnReplication(PersistentClass.java:830) 在 org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:848) 在 org.hibernate.mapping.PersistentClass.checkColumnReplication(PersistentClass.java:870) 在 org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:605) 位于org.hibernate.mapping.RootClass.validate(RootClass.java:265) org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329) 在 org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443) 在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ... 省略46个公共框架


据我所见,您有两个名为“locid”的列,一个是由ManyTone Relationship和您的注释
@JoinColumn(name=“locid”)
生成的,另一个是嵌入以locid为主键的TutrpLocYearlyPK生成的。您必须重命名其中一个。TutRptLocYearlyPK中的locid是TutLocation的外键。参考ERD,只创建了2个表,并且自动生成TutRptLocYearlyPK类,因为TutRptLocYearly将使用外键(locid)+年份作为其主键。
@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;
    }
}