Reputation: 16117
I'm using Query DSL with version 4.0.4 here's my dependencies;
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.0.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
and Here's a snippet of my QueryDSL query.
JPQLQuery query = new JPAQuery(em);
QQuotation quotation = QQuotation.quotation;
query.from(quotation).where(quotation.ticketNumber.like("this"))
However the query method doesn't have a list() method
when I line .where(quotation.ticketNumber.like("this"))
Here's the full code.
import com.querydsl.jpa.JPQLQuery;
import com.querydsl.jpa.impl.JPAQuery;
import org.app.now.domain.process.QQuotation;
import org.app.now.domain.process.Quotation;
import org.app.now.repo.QuotationRepoCustom;
import org.joda.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import javax.persistence.EntityManager;
import java.util.List;
public class QuotationRepoImpl implements QuotationRepoCustom {
@Autowired
private EntityManager em;
@Override
public List<Quotation> search(String ticketNumber, String description, LocalDateTime startDate, LocalDateTime endDate) {
System.out.println("Searching");
JPQLQuery query = new JPAQuery(em);
QQuotation quotation = QQuotation.quotation;
query.from(quotation).where(quotation.ticketNumber.like("this")).
return null;
}
}
Upvotes: 4
Views: 9368
Reputation: 22180
Like this
@Override
public List<Quotation> search(String ticketNumber, String description, LocalDateTime startDate, LocalDateTime endDate) {
JPQLQuery<Void> query = new JPAQuery<Void>(em);
QQuotation quotation = QQuotation.quotation;
return query.select(quotation)
.from(quotation)
.where(quotation.ticketNumber.like("this"))
.fetch();
}
Upvotes: 0
Reputation: 2663
Take a look to Fechable interface.
@Override
public List<Quotation> search(String ticketNumber, String description, LocalDateTime startDate, LocalDateTime endDate) {
System.out.println("Searching");
JPQLQuery query = new JPAQuery(em);
QQuotation quotation = QQuotation.quotation;
return query.from(quotation).where(quotation.ticketNumber.like("this")).fetch();
}
Good luck!
Upvotes: 1