Pessoal será que alguém poderia me ajudar?
estou tentando executar a seguinte query:
public List<CandidateSummary> searchCandidateByPosition(Position position, Opportunity opportunity){
if(position == null || position.getId() == null){
return new ArrayList<CandidateSummary>();
}
StringBuffer ejbql = new StringBuffer("select new CandidateSummary(");
ejbql.append("o , ");
ejbql.append("(select count(c) from Contact c where c.candidate = o and c.opportunity = :opContact), ");
ejbql.append("(select count(d) from OpportunityDelivery d where d.candidate = o and d.opportunity = :opDelivery)");
ejbql.append(") from ");
ejbql.append("Candidate o where o.id is not null and ");
ejbql.append("(exists (select cpp.position from o.candidatePositionList cpp where cpp.position = :position)) order by o.firstName");
Query query = em.createQuery(ejbql.toString());
query.setParameter("opContact", opportunity);
query.setParameter("opDelivery", opportunity);
query.setParameter("position", position);
return query.getResultList();
}
ou seja quero popular um outro objeto chamado CandidateSummary segue a classe na integra:
package br.com.walar.recruitment.model.candidate.helper;
import br.com.walar.recruitment.model.candidate.entities.Candidate;
public class CandidateSummary {
private Candidate candidate = new Candidate();
private Boolean contacted = false;
private Boolean delivered = false;
public CandidateSummary(Candidate candidate, Integer contact, Integer delivery) {
this.candidate = candidate;
this.contacted = (contact != 0);
this.delivered = (delivery != 0);
}
public void setCandidate(Candidate candidate) {
this.candidate = candidate;
}
public Candidate getCandidate() {
return candidate;
}
public void setContacted(Boolean contacted) {
this.contacted = contacted;
}
public Boolean isContacted() {
return contacted;
}
public void setDelivered(Boolean delivered) {
this.delivered = delivered;
}
public Boolean isDelivered() {
return delivered;
}
}
com as informações
do candidato , quantos contatos foram feitos referente a uma oportunidade que passo como parametro
e quantoso e-mail ja foram enviados para ele referente a mesma oportunidade;
porém só me da este erro:
Exception in thread "main" java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:742)
at br.com.walar.recruitment.JavaServiceFacade.searchCandidateByPosition(JavaServiceFacade.java:237)
at br.com.walar.recruitment.JavaServiceFacade.test(JavaServiceFacade.java:218)
at br.com.walar.recruitment.JavaServiceFacade.main(JavaServiceFacade.java:94)
Caused by: Exception [EclipseLink-8025] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing the query [select new CandidateSummary(o , 1 , 1) from Candidate o where o.id is not null and (exists (select cpp.position from o.candidatePositionList cpp where cpp.position = :position)) order by o.firstName], line 1, column 32: unexpected token [1].
Internal Exception: NoViableAltException(81!=[408:1: constructorItem returns [Object node] : (n= pathExprOrVariableAccess | n= aggregateExpression );])
at org.eclipse.persistence.exceptions.JPQLException.unexpectedToken(JPQLException.java:365)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.handleRecognitionException(JPQLParser.java:319)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.addError(JPQLParser.java:245)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.reportError(JPQLParser.java:362)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.constructorItem(JPQLParser.java:1845)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.constructorExpression(JPQLParser.java:1671)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.selectExpression(JPQLParser.java:1250)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.selectClause(JPQLParser.java:1097)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.selectStatement(JPQLParser.java:337)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.document(JPQLParser.java:261)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.parse(JPQLParser.java:133)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.buildParseTree(JPQLParser.java:94)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:203)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:170)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:134)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:95)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:80)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:740)
... 3 more
Caused by: NoViableAltException(81!=[408:1: constructorItem returns [Object node] : (n= pathExprOrVariableAccess | n= aggregateExpression );])
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.constructorItem(JPQLParser.java:1809)
... 16 more
Se puderem me ajudar ficarei muito grato por que to quebrando a cabeça com isso.