[ROO-3545] Dynamic finder generates invalid code Created: 21/Oct/14  Updated: 21/Oct/14

Status: Open
Project: Spring Roo
Component/s: DYNAMIC FINDERS
Affects Version/s: 1.2.5.RELEASE
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Mike Summers Assignee: Enrique Ruiz (DiSiD)
Resolution: Unresolved Votes: 0
Labels: roo
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 8.0, STS 3.6.2RELEASE, JDK 1.7.0.25


Reference URL: http://stackoverflow.com/questions/26472551/spring-roo-generating-invalid-finder/26480277#26480277

 Description   

Finder def

@RooJpaActiveRecord(finders = {"findIndividualJobsByIndividualAndIndividualJobType"})

Model field

@Enumerated(EnumType.STRING)
@ElementCollection(targetClass=IndividualJobType.class)
private List<IndividualJobType> individualJobType;

Generated finder

    public static TypedQuery<IndividualJob> IndividualJob.findIndividualJobsByIndividualAndIndividualJobType(Individual individual, List<IndividualJobType> individualJobType, String sortFieldName, String sortOrder) {
    if (individual == null) throw new IllegalArgumentException("The individual argument is required");
    if (individualJobType == null) throw new IllegalArgumentException("The individualJobType argument is required");
    EntityManager em = IndividualJob.entityManager();
    StringBuilder queryBuilder = new StringBuilder("SELECT o FROM IndividualJob AS o WHERE o.individual = :individual AND");
    for (int i = 0; i < individualJobType.size(); i++) {
        if (i > 0) queryBuilder.append(" AND");
        queryBuilder.append(" :individualJobType_item").append(i).append(" MEMBER OF o.individualJobType");
    }
    if (fieldNames4OrderClauseFilter.contains(sortFieldName)) {
        jpaQuery = jpaQuery + " ORDER BY " + sortFieldName;
        if ("ASC".equalsIgnoreCase(sortOrder) || "DESC".equalsIgnoreCase(sortOrder)) {
            queryBuilder.append(" " + sortOrder);
        }
    }
    TypedQuery<IndividualJob> q = em.createQuery(queryBuilder.toString(), IndividualJob.class);
    q.setParameter("individual", individual);
    int individualJobTypeIndex = 0;
    for (IndividualJobType _individualjobtype: individualJobType) {
        q.setParameter("individualJobType_item" + individualJobTypeIndex++, _individualjobtype);
    }
    return q;
}

Generated at Wed Dec 11 09:41:15 UTC 2019 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.