我有以下选择查询,对于第二个左连接中的此查询,我正在使用相同列的同一个表进行自联接。我希望同一个查询位于条件查询中。 我已将以下查询转换为条件查询但我收到以下错误
无法在此ManagedType上找到具有给定名称[org.hibernate.jpa.internal.metamodel.SingularAttributeImpl@1b3142f]的属性[com.glenwood.glaceemr.server.application.models.ProblemHistory]
select * from problem_report
left join problem_history a on problem_report_uniqueid=a.problem_history_problem_uniqueid
**left join problem_history b ON a.problem_history_problem_uniqueid = b.problem_history_problem_uniqueid**
在Spring Entity类中我做了spring
@Entity
@Table(name = "problem_history")
public class ProblemHistory implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator="problem_history_id_seq")
@SequenceGenerator(name ="problem_history_id_seq",
sequenceName="problem_history_id_seq", allocationSize=1)
@Column(name="problem_history_id")
private Integer problemHistoryId;
enter code here
@Column(name="problem_history_problem_uniqueid")
private Integer problemHistoryProblemUniqueid;
@ManyToOne
@JsonManagedReference
@JoinColumn(name="problem_history_problem_uniqueid",referencedColumnName="problem_history_problem_uniqueid",insertable=false, updatable=false)
private ProblemHistory problemhistoryRef;
在服务实施
中CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Object> cq = builder.createQuery();
Root<ProblemReport> root = cq.from(ProblemReport.class);
//Root<ProblemHistory> root1 = cq.from(ProblemHistory.class);
Join<ProblemReport,ProblemDataCheck> pblmDataCheckJoin=root.join("pbldatacheck",JoinType.LEFT);
Join<ProblemReport,ProblemHistory> pblmReportHistoryJoin=root.join(ProblemReport_.problemHistory,JoinType.LEFT);
Join<ProblemHistory,ProblemHistory> pblmhstryJoin=pblmReportHistoryJoin.join("problemhistoryRef",JoinType.LEFT);
让我知道无论如何都要在上面的条件查询中执行自我加入。