我必须使用QueryDSL / JPAQuery添加搜索功能。 搜索应使用由父ID组成的表:
ID LABEL P_ID
1 A null
2 AB 1
3 ABC 2
一个简单的SQL语句给出了正确的结果:
SELECT * FROM ACT
JOIN ORG DEPT ON ACT.ORGID = DEPT.ID
JOIN ORG DEPT2 ON DEPT.P_ID = DEPT2.ID
WHERE DEPT.P_ID = 123
我面临的问题是我必须使用现有的查询对象创建相应的QueryDSL / JPAQuery。
我的代码是:
query.join(act.org, dept).on(act.org.id.eq(dept.id)).where(dept.org.parent.eq(123));
在我的查询之前和之后,其他语句修改查询对象。 这会导致错误:
O DEBUG JPAQuery - 从档案档案中选择计数(不同的档案_)离开加入dossier_.acties actie_ inner join actie_.organisatieStructuur organisatieStructuur_ on actie_.organisatieStructuur.id = organisatieStructuur_.id其中dossier_.deleted =?1 and organisatieStructuur_.ouder = ?2
org.apache.openjpa.persistence.ArgumentException:“遇到”“在角色64处,但预期:[”,“,”GROUP“,”HAVING“,”INNER“,”JOIN“,”LEFT“, “订购”,“在哪里”,“。”解析JPQL时“select count(distinct dossier_) 来自档案档案_ left join dossier_.acties actie_ 内联盟actie_.organisatieStructuur organisatieStructuur_ on actie_.organisatieStructuur.id = organisatieStructuur_.id 其中dossier_.deleted =?1和organisatieStructuur_.ouder =?2“。
[已添加9月2日:] 域模型(仅显示包含字段的第一部分,由于大小而未显示其他getter / setter方法):
@Entity
public class Dossier extends AbstractEntity implements Serializable, HasCommunicaties {
private static final String SHAREPOINT_NR_FORMAT = "{0,number,0000}/{1,number,00}";
@Version
private long version;
private int jaar;
private int volgNummer;
private Status status;
public enum Status {
OPEN, AFGESLOTEN;
}
@Temporal(TemporalType.TIMESTAMP)
private Date datumStatus;
@NotNull
@Column(length = 5000)
@Size(max = 5000)
private String beschrijvingVaststelling;
@Column(length = 5000)
@Size(max = 5000)
private String oorzaakVaststelling;
@ManyToOne
private ZorgDomein zorgDomein;
@ManyToOne(fetch = FetchType.LAZY)
@NotNull
private Bron bron;
@ManyToOne
private KernWaarde kernWaarde;
private String pdca;
@Valid
@OneToMany(mappedBy = "dossier", cascade = CascadeType.ALL, orphanRemoval = true)
@Size(min = 1)
private List<PlaatsVaststelling> plaatsVaststellingen = new ArrayList<PlaatsVaststelling>();
@ManyToOne(fetch = FetchType.LAZY)
private Proces proces;
@NotNull
private String beheerder;
@Temporal(TemporalType.DATE)
@Past
private Date datumVaststelling;
@ManyToOne(fetch = FetchType.LAZY)
private TypeVaststelling typeVaststelling;
@ManyToOne(fetch = FetchType.LAZY)
private Prioritering prioritering;
@ManyToOne(fetch = FetchType.LAZY)
private AuditRapport auditRapport;
@OneToMany(mappedBy = "dossier", cascade = CascadeType.ALL)
@OrderBy("volgnummer")
@Valid
private List<Actie> acties = new ArrayList<Actie>();
@OneToMany(mappedBy = "dossier")
@OrderBy("datum desc")
private List<Communicatie> communicaties = new ArrayList<Communicatie>();
@OneToMany(mappedBy = "dossier", cascade = CascadeType.ALL)
@OrderBy("datum desc")
private List<Historiek> historieks = new ArrayList<Historiek>();
private boolean vertrouwelijk;
@ElementCollection
private List<String> beheerders = new ArrayList<String>();
@ElementCollection
private List<String> lezers = new ArrayList<String>();
private boolean mailPVAVerstuurd;
private Date datumAanpakTegen;
private boolean deleted;
答案 0 :(得分:0)
这个SQL
SELECT * FROM ACT
JOIN ORG DEPT ON ACT.ORGID = DEPT.ID
JOIN ORG DEPT2 ON DEPT.P_ID = DEPT2.ID
WHERE DEPT.P_ID = 123
可以通过
表达QAct act = QAct.act;
QOrg dept = new QOrg("dept");
QOrg dept2 = new QOrg("dept2");
query.from(act)
.join(act.org, dept)
.join(dept.p, dept2)
.where(dept2.p.id.eq(123))
.list(act);
我不确定如何将SQL映射到您的域模型,这就是我使用接近SQL关系的实体名称的原因。