小编典典

找不到具有逻辑名称的列

hibernate

我有5个表,每个表与下一个表有一对多的关系
。project_t-> project_level1_t-> project_level2_t-> project_level3_t->
project_level4_t
我想让用户hibernate这些表

CREATE TABLE project_t
(
  projectid serial NOT NULL,
  address1 character varying(128),
  postcode character varying(7),
  city character varying(64),
  level_four_name character varying(128),
  CONSTRAINT project_t_pkey PRIMARY KEY (projectid),
  CONSTRAINT projectcode_unique UNIQUE (projectcode)
)

和project_level1_t

CREATE TABLE project_level1_t
(
  projectlevel1id integer NOT NULL DEFAULT nextval('project_level1_t_projectlevel1pk_seq'::regclass),
  levelname character varying(256),
  projectid integer,
  CONSTRAINT project_level1_t_pkey PRIMARY KEY (projectlevel1id),
  CONSTRAINT project_level1_t_project_t_fkey FOREIGN KEY (projectid)
      REFERENCES project_t (projectid) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)

和project_level2_t

CREATE TABLE project_level2_t
(
  projectlevel2id integer NOT NULL DEFAULT nextval('project_level2_t_projectlevel2_seq'::regclass),
  levelname character varying(256),
  projectlevel1id integer,
  CONSTRAINT project_level2_t_pkey PRIMARY KEY (projectlevel2id),
  CONSTRAINT project_level2_t_projec_level_1_fkey FOREIGN KEY (projectlevel1id)
      REFERENCES project_level1_t (projectlevel1id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION

这是存储库文件

   package ma.eurnet.mp.tables.model;

    import javax.persistence.GenerationType;

    @JsonAutoDetect
    @Entity
    @Table(name = "project_t")
    public class ProjectRepository implements Serializable {

        private static final long serialVersionUID = 1L;

        public ProjectRepository() {
        }

        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "projectid")
        private Long projectId;

        @OneToMany(fetch = FetchType.EAGER, mappedBy="project")
        @JsonIgnore
        private List<ProjectLevel1Repository> projectlevel1 = new ArrayList<ProjectLevel1Repository>();

        public Long getProjectId() {
            return projectId;
        }

        public void setProjectId(Long projectId) {
            this.projectId = projectId;
        }

        public List<ProjectLevel1Repository> getProjectlevel1() {
            return projectlevel1;
        }

        public void setProjectlevel1(List<ProjectLevel1Repository> projectlevel1) {
            this.projectlevel1 = projectlevel1;
        }

 package ma.eurnet.mp.tables.model;

    @JsonAutoDetect
    @Entity
    @SequenceGenerator(name = "projectLevel1Sequence", sequenceName = "project_level1_t_projectlevel1pk_seq", allocationSize = 1)
    @Table(name="project_level1_t")
    public class ProjectLevel1Repository implements Serializable {

        private static final long serialVersionUID = 1L;

        public ProjectLevel1Repository() {
        }

        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "projectLevel1Sequence")
        @Column(name = "projectlevel1id")
        private Long projectLevel1Id;

        @ManyToOne
        @JoinColumn(name="projectid", referencedColumnName = "projectid")
        @JsonIgnore
        private ProjectRepository project;

    @OneToMany(fetch = FetchType.EAGER, mappedBy="projectlevel1id")
        @JsonIgnore
        private List<ProjectLevel2Repository> projectlevel2 = new ArrayList<ProjectLevel2Repository>();

        public List<ProjectLevel2Repository> getProjectlevel2() {
            return projectlevel2;
        }

        public Long getProjectLevel1Id() {
            return projectLevel1Id;
        }


        public void setProjectLevel1Id(Long projectLevel1Id) {
            this.projectLevel1Id = projectLevel1Id;
        }


        public ProjectRepository getProject() {
            return project;
        }


        public void setProject(ProjectRepository project) {
            this.project = project;
        }




    }

package ma.eurnet.mp.tables.model;

import java.io.Serializable;


@JsonAutoDetect
@Entity
@SequenceGenerator(name = "projectLevel2Sequence", sequenceName = "project_level2_t_projectlevel2_seq", allocationSize = 1)
@Table(name="project_level2_t")
public class ProjectLevel2Repository implements Serializable {

    private static final long serialVersionUID = 1L;

    public ProjectLevel2Repository() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "projectLevel2Sequence")
    @Column(name = "projectlevel2id")
    private Long projectLevel2Id;

    @Column(name = "levelname")
    private String levelName;


    @Column(name = "created_by")
    private String createdBy;

    @Column(name = "creation_date")
    private String creationDate;


    @ManyToOne
    @JoinColumn(name="projectlevel1id", referencedColumnName = "projectlevel1id")
    @JsonIgnore
    private ProjectRepository projectlevel1id;

    public Long getProjectLevel2Id() {
        return projectLevel2Id;
    }


    public void setProjectLevel2Id(Long projectLevel2Id) {
        this.projectLevel2Id = projectLevel2Id;
    }


    public String getLevelName() {
        return levelName;
    }


    public void setLevelName(String levelName) {
        this.levelName = levelName;
    }


    public String getCreatedBy() {
        return createdBy;
    }


    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }


    public String getCreationDate() {
        return creationDate;
    }


    public void setCreationDate(String creationDate) {
        this.creationDate = creationDate;
    }


    public ProjectRepository getProjectlevel1id() {
        return projectlevel1id;
    }


    public void setProjectlevel1id(ProjectRepository projectlevel1id) {
        this.projectlevel1id = projectlevel1id;
    }



}

但是当我运行我的应用程序时,出现此错误

org.hibernate.MappingException:无法在org.hibernate.mapping.Table(project_t)及其相关的超表和辅助表中找到逻辑名称为projectlevel1id的列

我该如何解决这个问题


阅读 301

收藏
2020-06-20

共1个答案

小编典典

在其中ProjectLevel2Repository,有一个指向ProjectRepository使用不存在的@JoinColumnnamed
的映射projectlevel1id。根据您的描述,这应该映射到ProjectLevel1Repository

@ManyToOne
@JoinColumn(name="projectlevel1id", referencedColumnName = "projectlevel1id")
@JsonIgnore
private ProjectLevel1Repository projectlevel1;
2020-06-20