JPA中的标识符无效

时间:2015-01-25 21:12:26

标签: java hibernate jpa

EnfInspPrgm实体与EnfInspPmSc实体之间存在多对多关系。

以下是实体类

    public class EnfInspPrgm implements Serializable {
        private static final long serialVersionUID = 1L;

        @Id
        @Column(name="PRM_ID")
        private long prmId;

        @Column(name="AREA_ID")
        private long areaId;

        //bi-directional many-to-one association to EnfInspPmSc
        @OneToMany(mappedBy="enfInspPrgm")
        private List<EnfInspPmSc> enfInspPmScs;

        public EnfInspPrgm() {
        }

        public long getPrmId() {
            return this.prmId;
        }

        public void setPrmId(long prmId) {
            this.prmId = prmId;
        }

        public long getAreaId() {
            return this.areaId;
        }

        public void setAreaId(long areaId) {
            this.areaId = areaId;
        }

        public List<EnfInspPmSc> getEnfInspPmScs() {
            return this.enfInspPmScs;
        }

        public void setEnfInspPmScs(List<EnfInspPmSc> enfInspPmScs) {
            this.enfInspPmScs = enfInspPmScs;
        }

        public EnfInspPmSc addEnfInspPmSc(EnfInspPmSc enfInspPmSc) {
            getEnfInspPmScs().add(enfInspPmSc);
            enfInspPmSc.setEnfInspPrgm(this);

            return enfInspPmSc;
        }

        public EnfInspPmSc removeEnfInspPmSc(EnfInspPmSc enfInspPmSc) {
            getEnfInspPmScs().remove(enfInspPmSc);
            enfInspPmSc.setEnfInspPrgm(null);

            return enfInspPmSc;
        }

    }

@Entity
@Table(name="ENF_INSP_PM_SC")
public class EnfInspPmSc implements Serializable {
    private static final long serialVersionUID = 1L;
    //bi-directional many-to-one association to InspectionSource
        @ManyToOne(optional=false)
        @JoinColumn(name="ENF_INSP_SOURCE_ID")
        private InspectionSource inspectionSource;

    @Column(name="ENF_INSP_PRM_SRC_ID")
    private long enfInspPrmSrcId;

    @ManyToOne
    @JoinColumn(name="PRM_ID")
    private EnfInspPrgm enfInspPrgm;

    public EnfInspPmSc() {
    }
}

@Entity
@Table(name = "REF_ENF_INSP_SOURCE")
public class InspectionSource implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "ENF_INSP_SOURCE_ID")
    private Integer id;


    // bi-directional many-to-one association to User
    @ManyToOne
    @JoinColumn(name = "CREATED_BY_USER_ID")
    private User createdUser;

    // bi-directional many-to-one association to User
    @ManyToOne
    @JoinColumn(name = "MODIFIED_BY_USER_ID")
    private User modifiedUser;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public User getCreatedUser() {
        return createdUser;
    }

    public void setCreatedUser(User createdUser) {
        this.createdUser = createdUser;
    }

    public String getCreatedByName() {
        return createdByName;
    }

    public void setCreatedByName(String createdByName) {
        this.createdByName = createdByName;
    }

    public User getModifiedUser() {
        return modifiedUser;
    }

    public void setModifiedUser(User modifiedUser) {
        this.modifiedUser = modifiedUser;
    }

}

我正在创建一个JPA存储库来选择EnfInspPrgm个实体。但它导致错误

Invalid identifier for enfInspPrgm, ENF_INSP_SOURCE_ID

请帮助我并解决此问题。

1 个答案:

答案 0 :(得分:0)

您的代码似乎缺少一些声明。例如,EnfInspPrgm没有使用@Entity进行注释。

此外,在EnfInspPmSc中,您没有为字段添加getter和setter。把getEnfInspPrgm和setEnfInspPrgm放在一起。对其他领域也这样做。

请注意,JPA声明将在所有情况下都转换为本机sql。这种关系的所有者总是在一边有一个FK的许多方面。因此,如果EnfInspPmSc没有那些setter和getter,你将无法访问这两个表中的任何数据。