2

Im new to query dsl.Im using Spring repositories to get the result set.And one case i have to get the maximum of a column and get the fields in to an entity.My predicate code is below.I get error once i run this code.

public static  Predicate getMaximum(){
 QUserDetails details = QUserDetails.userDetails;
 return details.id.eq(details.id.max());
 }

And this is how i fetch my resultset using spring jpa

public UserDetails findByCustomerId(Predicate predicate);

And this is the error i get:

org.springframework.data.mapping.PropertyReferenceException: No property find found for type com.example.entity.UserDetails.Can anyone help me acheive what i want here.

2 Answers2

2

You have to define a QueryDslJpaRepository which adds implementation for QueryDslPredicateExecutor

http://docs.spring.io/spring-data/jpa/docs/1.5.0.M1/api/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.html

You can see a tutorial here:

http://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-part-eight-adding-functionality-to-a-repository/

Andres
  • 10,561
  • 4
  • 45
  • 63
0

From the QueryDSL email group, apparently what you have to do to select the max ID is this:

from(entity).singleResult(entity.id.max())

So it's

JPAQuery jpaQuery = new JPAQuery(entityManager);
QEntity qEntity = QEntity.entity;
Long maxId = query.from(qEntity).singleResult(qEntity.id.max());
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428