我有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的列
我该如何解决这个问题
在其中ProjectLevel2Repository
,有一个指向ProjectRepository
使用不存在的@JoinColumn
named
的映射projectlevel1id
。根据您的描述,这应该映射到ProjectLevel1Repository
@ManyToOne
@JoinColumn(name="projectlevel1id", referencedColumnName = "projectlevel1id")
@JsonIgnore
private ProjectLevel1Repository projectlevel1;
问题内容: 您好我的表格如下: 1- medical_company : account_entity* 表 account_entity_id 列上的medical_company_id 外键 (不是pk) *** 第1栏 专栏2 第三栏 2- account_entity : account_entity_id (pk) 第1栏 专栏2 第三栏 3 人同行: person_id (pk) 第1
有两个表。酒店内的地址。我已经提到了OneTo很多关系。但是编译器抛出错误。 创建名为entityManagerFactory的bean时出错,该bean在类路径资源[org/springFramework/boot/autoconfiure/orm/jpa/HibernateJpaConfiguration.class]中定义:调用init方法失败;嵌套异常org.hibernate.Mappi
currency_pair的DDL 我的实体类如下:- 货币实体- 注意:我无法更改ddl查询,那么我可以做什么来修复实体类
这与以下问题类似: 问题A 在中,我有: 然后,在类中,我有:
冬眠5.2.12.1决赛 我想用CriteriaBuilder替换depreracted session.createCriteria(参见org.hibernate.Criteria),我有以下异常 在此ManagedType[com…DonneReference]上找不到具有给定名称[filtre]的属性 上: 其中(builder.equal(root.get(“filter”),filte