When i try to use Querydsl as shown in Spring reference Spring 1.10.4.RELEASE reference - i get some errors from IDE: Cannot resolve method findAll(predicate). I changed import to com.mysema.query.types.Predicate. Now method looks fine. But i cant resolve problem with:
Predicate predicate = user.getUsername().equalsIgnoreCase(username).and((user.getId().equals(userid)).not);
I got errors: cannot resolve method: and, cannot resolve method not.
Some from reference: Example 32. Querydsl integration on repositories
interface UserRepository extends CrudRepository<User, Long>, QueryDslPredicateExecutor<User> {
}
The above enables to write typesafe queries using Querydsl Predicate s.
Predicate predicate = user.firstname.equalsIgnoreCase("dave")
.and(user.lastname.startsWithIgnoreCase("mathews"));
userRepository.findAll(predicate);
But example is incorrect. Anybody know how to use this?
You are probably using the wrong user
object to start with. I assume you are currently using your domain class User
but you need to use the class generated by Querydsl, normally named QUser
.
See https://github.com/querydsl/querydsl/tree/master/querydsl-jpa for example code.
See QueryDsl - How to create Q classes with maven? for how to generate the necessary classes with Querydsl.