Spring 数据 JPA - 方法名称 - @ManyToOne
Spring Data JPA - Method Name - @ManyToOne
我有一个实体 CpoPipeline 与 ManyToOne 与 CpoEnvironment 的关系:
@Entity
@Table(name = "cpo_pipeline", catalog = "cup_orchestrator")
public class CpoPipeline implements java.io.Serializable {
private String pipelineId;
private String pipelineName;
private CpoEnvironment cpoEnvironment;
@Column(name = "pipeline_id", unique = true, nullable = false)
public String getPipelineId() {
return this.pipelineId;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "environment_id", nullable = false)
public CpoEnvironment getCpoEnvironment() {
return this.cpoEnvironment;
}
//Getters and Setters
}
实体 CpoEnvironment:
@Entity
@Table(name = "cpo_environment", catalog = "cup_orchestrator")
public class CpoEnvironment implements java.io.Serializable {
private String environmentId;
private String environment;
private Set<CpoPipeline> cpoPipelines = new HashSet<CpoPipeline>(0);
@Id
@Column(name = "environment_id", unique = true, nullable = false)
public String getEnvironmentId() {
return this.environmentId;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "cpoEnvironment")
public Set<CpoPipeline> getCpoPipelines() {
return this.cpoPipelines;
}
//Getters and Setters
}
具有方法名称的此实体的存储库:
@Repository
public interface PipelineRep extends JpaRepository<CpoPipeline, String> {
Optional<CpoPipeline> findByPipelineIdAndEnvironmentId(String pipelineId, String environmentId);
}
错误:原因:org.springframework.data.mapping.PropertyReferenceException:未找到类型 CpoPipeline
的 属性 environmentId
如何使用实体中的一个字段和关系中的一个字段创建方法名称?可能吗?
可以,要使用 CpoEnvironment
实体的 environmentId
使用这种方式 CpoEnvironmentEnvironmentId
Optional<CpoPipeline> findByPipelineIdAndCpoEnvironmentEnvironmentId(String pipelineId, String environmentId);
我有一个实体 CpoPipeline 与 ManyToOne 与 CpoEnvironment 的关系:
@Entity
@Table(name = "cpo_pipeline", catalog = "cup_orchestrator")
public class CpoPipeline implements java.io.Serializable {
private String pipelineId;
private String pipelineName;
private CpoEnvironment cpoEnvironment;
@Column(name = "pipeline_id", unique = true, nullable = false)
public String getPipelineId() {
return this.pipelineId;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "environment_id", nullable = false)
public CpoEnvironment getCpoEnvironment() {
return this.cpoEnvironment;
}
//Getters and Setters
}
实体 CpoEnvironment:
@Entity
@Table(name = "cpo_environment", catalog = "cup_orchestrator")
public class CpoEnvironment implements java.io.Serializable {
private String environmentId;
private String environment;
private Set<CpoPipeline> cpoPipelines = new HashSet<CpoPipeline>(0);
@Id
@Column(name = "environment_id", unique = true, nullable = false)
public String getEnvironmentId() {
return this.environmentId;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "cpoEnvironment")
public Set<CpoPipeline> getCpoPipelines() {
return this.cpoPipelines;
}
//Getters and Setters
}
具有方法名称的此实体的存储库:
@Repository
public interface PipelineRep extends JpaRepository<CpoPipeline, String> {
Optional<CpoPipeline> findByPipelineIdAndEnvironmentId(String pipelineId, String environmentId);
}
错误:原因:org.springframework.data.mapping.PropertyReferenceException:未找到类型 CpoPipeline
的 属性 environmentId如何使用实体中的一个字段和关系中的一个字段创建方法名称?可能吗?
可以,要使用 CpoEnvironment
实体的 environmentId
使用这种方式 CpoEnvironmentEnvironmentId
Optional<CpoPipeline> findByPipelineIdAndCpoEnvironmentEnvironmentId(String pipelineId, String environmentId);