0

I have two entities, One saves the basic case related data and other saves all the updates for a certain case.

@Entity(name = "Case")
@EntityListeners(AuditingEntityListener.class)
@NamedQueries({
public class Case extends AbstractAuditableEntity implements Serializable {

    @Column(nullable = false)
    private Long referenceId; 

    @ManyToOne(optional = false)
    private Incident Incident;

    @OneToMany(targetEntity = CaseUpdate.class, orphanRemoval = true, cascade = CascadeType.ALL, mappedBy = "case")
    @JoinColumn(name="case", nullable = false)
    @OrderBy("created desc")
    private List<CaseUpdate> caseUpdates = new ArrayList<CaseUpdate>();

The other class with ManyToOne relationship is as follows

@Entity(name = "CaseUpdate")
@EntityListeners(AuditingEntityListener.class)

public class CaseUpdate extends AbstractAuditableEntity implements Serializable {

    public CaseUpdate() {
    }

    @Id
    @GeneratedValue
    private Long id;

    @Column
    private String status;

    @Column(nullable = false)
    private String type;

    @Column(columnDefinition = "TEXT")
    private String description;

    @Column(name = "created",nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date created;

    @Column
    @Temporal(TemporalType.DATE)
    private Date restoreDate;

    @Column
    @Temporal(TemporalType.DATE)
    private Date responseDate;

    @Column
    @Temporal(TemporalType.DATE)
    private Date commitmentDate;

    @JoinColumn(name="caseUpdates")
    @ManyToOne(optional = false)
    private Case case;

I am trying to search the Case table and CaseUpdate table using BooleanExpression to build queries. When it tries to search I get exception

Caused by: org.eclipse.persistence.exceptions.QueryException: Exception Description: index() requires QueryKeyExpression with CollectionMapping that has non-null list order column. [org.eclipse.persistence.mappings.OneToManyMapping[caseUpdates]] in does not meet this condition in [ Query Key caseUpdates Base au.net.iinet.fms.data.entities.Case] Query: ReportQuery(referenceClass=Case jpql= "select count(case) from Case case left join case.caseUpdates as case_caseUpdates_0 where index(case_caseUpdates_0) = ?1 and case.faultIncident.faultDomain = ?2 and case_caseUpdates_0.status = ?3")

The following code is used to create the search criteria

    BooleanExpression overallCriteria = null;
if (params.getStatus() != null && !params.getStatus().isEmpty()) {
      overallCriteria  = QCase.case.caseUpdates.get(0).status.eq(params.getStatus());
    }

The QCase class is generated using Querydsl. I am not sure what this exception means and how to fix it, any ideas?

4
  • Since you can't be bothered to put the JPQL clearly, here it is select count(case) from Case case left join case.caseUpdates as case_caseUpdates_0 where index(case_caseUpdates_0) = ?1 and case.faultIncident.faultDomain = ?2 and case_caseUpdates_0.status = ?3 and you can see easily enough that you have INDEX(case_caseUpdates_0), whereas INDEX is supposed to take a collection field (e.g caseUpdates) May 23, 2017 at 6:57
  • I am trying to understand this code which is already written, the caseUpdates is actually a List in entity Case. This is as far as I understand is trying to retrieve the last CaseUpdate from the array.
    – Saba
    May 23, 2017 at 7:50
  • So you're using QueryDSL to generate this, and NOT the JPA API. Tags now updated May 23, 2017 at 8:07
  • I have added the code that actually creates the query for searching. The JPQL was automatically generated, so I need to find the root cause and how to fix that.
    – Saba
    May 23, 2017 at 8:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.