記錄一下 spring boot jpa 外連接的 EntityGraph 寫法

實體類: 

package com.jintel.ct.entity;

import javax.persistence.*;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @date :2019/6/26
 */
@NamedEntityGraph(
		name = "CXCustomeStudiesNctIdOne.leftJoinList",
		attributeNodes = {
				@NamedAttributeNode("conditionss"),
				@NamedAttributeNode("cxCustomeDesignss"),
				@NamedAttributeNode("cxCustomeFacilities"),
				@NamedAttributeNode("cxCustomeInterventionss"),
				@NamedAttributeNode("documentss"),
				@NamedAttributeNode("idInformations"),
				@NamedAttributeNode("outcomeMeasurementss"),
				@NamedAttributeNode("sponsorss")
		}
)
@Entity
@Table(name = "ct_custom_studies")
public class CXCustomeStudiesNctIdOne {


	@Id
	@Column(name = "nct_id")
	private String nctId;
	@Column(name = "title")
	private String title;
	@Column(name = "status")
	private String status;
	@Column(name = "study_type")
	private String studyType;
	@Column(name = "phase")
	private String phase;
	@Column(name = "enrollment")
	private Integer numberEnrolled;
	@Column(name = "start_date")
	private Date studyStart;
	@Column(name = "completion_date")
	private Date studyCompletion;
	@Column(name = "study_result")
	private String studyResult;
	@Column(name = "primary_completion_date")
	private Date primaryCompletion;
	@Column(name = "first_posted")
	private Date firstPosted;
	@Column(name = "last_update_posted")
	private Date lastUpdatePosted;
	@Column(name = "results_first_posted")
	private Date resultsFirstPosted;
	@Column(name = "acronym")
	private String titleAcronym;
	@Column(name = "url")
	private String url;
	@Column(name = "age")
	private String age;
	@Column(name = "gender")
	private String gender;
	@Column(name = "trial_create_date")
	private Date trialCreateDate;
	@Column(name = "update_date")
	private Date updateDate;
	@Column(name = "sampling_method")
	private String samplingMethod;
	@Column(name = "inclusion")
	private String inclusion;
	@Column(name = "exclusion")
	private String exclusion;
	@Column(name = "accept_healthy_vol")
	private String acceptHealthyVol;
	@Column(name = "brief_summary")
	private String briefSummary;
	@Column(name = "rank")
	private Integer rank;
	@Column(name = "scope")
	private String scope;



	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "nct_id", referencedColumnName = "nct_id")
	private Set<Conditions> conditionss = new LinkedHashSet<>();

	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "nct_id", referencedColumnName = "nct_id")
	private Set<CXCustomeDesigns> cxCustomeDesignss = new LinkedHashSet<>();

	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "nct_id", referencedColumnName = "nct_id")
	private Set<CXCustomeFacilities> cxCustomeFacilities = new LinkedHashSet<>();

	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "nct_id", referencedColumnName = "nct_id")
	private Set<CXCustomeInterventions> cxCustomeInterventionss = new LinkedHashSet<>();

	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "nct_id", referencedColumnName = "nct_id")
	private Set<Documents> documentss = new LinkedHashSet<>();

	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "nct_id", referencedColumnName = "nct_id")
	private Set<IdInformation> idInformations = new LinkedHashSet<>();

	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "nct_id", referencedColumnName = "nct_id")
	private Set<OutcomeMeasurements> outcomeMeasurementss = new LinkedHashSet<>();

	@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "nct_id", referencedColumnName = "nct_id")
	private Set<Sponsors> sponsorss = new LinkedHashSet<>();

	public String getNctId() {
		return nctId;
	}

	public void setNctId(String nctId) {
		this.nctId = nctId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getStudyType() {
		return studyType;
	}

	public void setStudyType(String studyType) {
		this.studyType = studyType;
	}

	public String getPhase() {
		return phase;
	}

	public void setPhase(String phase) {
		this.phase = phase;
	}

	public Integer getNumberEnrolled() {
		return numberEnrolled;
	}

	public void setNumberEnrolled(Integer numberEnrolled) {
		this.numberEnrolled = numberEnrolled;
	}

	public Date getStudyStart() {
		return studyStart;
	}

	public void setStudyStart(Date studyStart) {
		this.studyStart = studyStart;
	}

	public Date getStudyCompletion() {
		return studyCompletion;
	}

	public void setStudyCompletion(Date studyCompletion) {
		this.studyCompletion = studyCompletion;
	}

	public Date getPrimaryCompletion() {
		return primaryCompletion;
	}

	public void setPrimaryCompletion(Date primaryCompletion) {
		this.primaryCompletion = primaryCompletion;
	}

	public Date getFirstPosted() {
		return firstPosted;
	}

	public void setFirstPosted(Date firstPosted) {
		this.firstPosted = firstPosted;
	}

	public Date getLastUpdatePosted() {
		return lastUpdatePosted;
	}

	public void setLastUpdatePosted(Date lastUpdatePosted) {
		this.lastUpdatePosted = lastUpdatePosted;
	}

	public Date getResultsFirstPosted() {
		return resultsFirstPosted;
	}

	public void setResultsFirstPosted(Date resultsFirstPosted) {
		this.resultsFirstPosted = resultsFirstPosted;
	}

	public String getTitleAcronym() {
		return titleAcronym;
	}

	public void setTitleAcronym(String titleAcronym) {
		this.titleAcronym = titleAcronym;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Set<Conditions> getConditionss() {
		return conditionss;
	}

	public void setConditionss(Set<Conditions> conditionss) {
		this.conditionss = conditionss;
	}

	public Set<CXCustomeDesigns> getCxCustomeDesignss() {
		return cxCustomeDesignss;
	}

	public void setCxCustomeDesignss(Set<CXCustomeDesigns> cxCustomeDesignss) {
		this.cxCustomeDesignss = cxCustomeDesignss;
	}


	public Set<CXCustomeFacilities> getCxCustomeFacilities() {
		return cxCustomeFacilities;
	}

	public void setCxCustomeFacilities(Set<CXCustomeFacilities> cxCustomeFacilities) {
		this.cxCustomeFacilities = cxCustomeFacilities;
	}

	public Set<CXCustomeInterventions> getCxCustomeInterventionss() {
		return cxCustomeInterventionss;
	}

	public void setCxCustomeInterventionss(Set<CXCustomeInterventions> cxCustomeInterventionss) {
		this.cxCustomeInterventionss = cxCustomeInterventionss;
	}

	public Set<Documents> getDocumentss() {
		return documentss;
	}

	public void setDocumentss(Set<Documents> documentss) {
		this.documentss = documentss;
	}

	public Set<IdInformation> getIdInformations() {
		return idInformations;
	}

	public void setIdInformations(Set<IdInformation> idInformations) {
		this.idInformations = idInformations;
	}

	public Set<OutcomeMeasurements> getOutcomeMeasurementss() {
		return outcomeMeasurementss;
	}

	public void setOutcomeMeasurementss(Set<OutcomeMeasurements> outcomeMeasurementss) {
		this.outcomeMeasurementss = outcomeMeasurementss;
	}

	public Set<Sponsors> getSponsorss() {
		return sponsorss;
	}

	public void setSponsorss(Set<Sponsors> sponsorss) {
		this.sponsorss = sponsorss;
	}

	public String getStudyResult() {
		return studyResult;
	}

	public void setStudyResult(String studyResult) {
		this.studyResult = studyResult;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public Date getTrialCreateDate() {
		return trialCreateDate;
	}

	public void setTrialCreateDate(Date trialCreateDate) {
		this.trialCreateDate = trialCreateDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getSamplingMethod() {
		return samplingMethod;
	}

	public void setSamplingMethod(String samplingMethod) {
		this.samplingMethod = samplingMethod;
	}

	public String getInclusion() {
		return inclusion;
	}

	public void setInclusion(String inclusion) {
		this.inclusion = inclusion;
	}

	public String getExclusion() {
		return exclusion;
	}

	public void setExclusion(String exclusion) {
		this.exclusion = exclusion;
	}

	public String getAcceptHealthyVol() {
		return acceptHealthyVol;
	}

	public void setAcceptHealthyVol(String acceptHealthyVol) {
		this.acceptHealthyVol = acceptHealthyVol;
	}

	public String getBriefSummary() {
		return briefSummary;
	}

	public void setBriefSummary(String briefSummary) {
		this.briefSummary = briefSummary;
	}

	public Integer getRank() {
		return rank;
	}

	public void setRank(Integer rank) {
		this.rank = rank;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}
}

repository:

package com.jintel.ct.repository;

import com.jintel.ct.entity.CXCustomeStudiesNctIdOne;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;

/**
 * @date :2019/6/26
 */
public interface TrialsLeftJoinByOneRepository extends JpaRepository<CXCustomeStudiesNctIdOne,Integer>{

	@EntityGraph(value = "CXCustomeStudiesNctIdOne.leftJoinList")
	CXCustomeStudiesNctIdOne findByNctId(String nctId);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章