2016-09-06 65 views
1

找到專欄中,我有5個表每個表都有關係一對多與鄰桌
Project_t - > project_level1_t - > project_level2_t - > project_level3_t - > project_level4_t
我希望用戶使用這些表冬眠無法與邏輯名稱

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; 
    } 



} 

但是當我運行我的應用程序得到這個錯誤

組織。 HIB ernate.MappingException:無法找到邏輯名稱列:projectlevel1id在org.hibernate.mapping.Table(project_t)及其相關supertables和輔助表

我怎麼能解決這個問題,請

+0

謝謝,你救了我的一天。我修復了我的數據模型設計。 –

回答

1

ProjectLevel2Repository你有使用名爲projectlevel1id的不存在的@JoinColumn映射到ProjectRepository。從你所描述的,這應該被映射到ProjectLevel1Repository

@ManyToOne 
@JoinColumn(name="projectlevel1id", referencedColumnName = "projectlevel1id") 
@JsonIgnore 
private ProjectLevel1Repository projectlevel1; 
+0

ya在ProjectLevel2Repository我想映射到ProjectLevel1Repository,並且我不知道該怎麼做 –

+0

嘗試從我的答案映射,它工作嗎? –

+0

你救了我的日子非常感謝你 –