java.lang.NoSuchMethodError: com.mysema.query.jpa.JPQLQuery.offset(J)Lcom/mysema/query/Query;

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • I have a Jpa repository that utilizes QueryDSL's fluent API: {code:title=IUserRepository.java|borderStyle=solid} public interface IUserRepository extends JpaRepository<User, Long>, QueryDslPredicateExecutor<User> {code} Then I have a service that reads records from the repository via the findAll() method. I have a requirement that the fields must be dynamic and the records are pageable: {code:title=UserService.java|borderStyle=solid} @Service @Transactional public class UserService implements IUserService { @Autowired private IUserRepository userRepository; @Autowired private EntityManagerFactory emf; @Override public Page<User> readFromRepository(String username, Pageable page) { PathBuilder<User> entityPath = new PathBuilder<User>(User.class, "user"); StringPath path = entityPath.get(new StringPath("username")); BooleanExpression hasUsername = path.eq(username); BooleanBuilder builder = new BooleanBuilder(); builder.and(hasUsername); return userRepository.findAll(builder, page); } ... } {code} However an exception is thrown whenever that method is called: {noformat} java.lang.NoSuchMethodError: com.mysema.query.jpa.JPQLQuery.offset(J)Lcom/mysema/query/Query; at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.applyPagination(QueryDslJpaRepository.java:168) at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.findAll(QueryDslJpaRepository.java:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:322) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:307) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy24.findAll(Unknown Source) at org.demo.service.UserService.readFromRepository(UserService.java:43) {noformat} I tried digging into the code and the source and I can't find the reasons why. The internal implementation doesn't show any missing methods. I have checked my jars but I didn't find any old dependencies. I tested my project both at home and at work (Ubuntu, Windows, proxied, non-proxied environments). But I keep getting the same exception. When I check the following: {noformat} org.springframework.data.jpa.repository.support.QueryDslJpaRepository.applyPagination(QueryDslJpaRepository.java:168) {noformat} {code:title=QueryDslJpaRepository.java|borderStyle=solid} protected JPQLQuery applyPagination(JPQLQuery query, Pageable pageable) { if (pageable == null) { return query; } query.offset(pageable.getOffset()); query.limit(pageable.getPageSize()); return applySorting(query, pageable.getSort()); } {code} As a workaround, I did the following code: {code:title=UserService.java|borderStyle=solid} @Service @Transactional public class UserService implements IUserService { @Autowired private IUserRepository userRepository; @Autowired private EntityManagerFactory emf; ... @Override public List<User> readFromEntityManager(String username, Pageable page) { PathBuilder<User> entityPath = new PathBuilder<User>(User.class, "user"); StringPath path = entityPath.get(new StringPath("username")); BooleanExpression hasUsername = path.ne(username); BooleanBuilder builder = new BooleanBuilder(); builder.and(hasUsername); EntityManager em = emf.createEntityManager(); JPQLQuery result = new JPAQuery(em).from(entityPath).where(builder); if (page != null) { result.offset(page.getOffset()); result.limit(page.getPageSize()); } return result.list(entityPath); } ... } {code} And it works perfectly. I tried to match as possible the original Spring JPA implementation. I don't really know what's wrong with the findAll() method, but directly calling the EntityManagerFactory somehow did the trick. I have attached a strip-down version of my webapp. It's a Maven project with unit tests included. Just run Maven test to verify the error. You need to have MySQL and create a db "testdb". No data is needed but you can prepopulate them. There's a data.sql inside the classpath. (I'm trying to initialize the db with jdbc:initialize-database but it keeps throwing an error. You might wanna take a peek of that error if you like). By the way my Maven properties: {noformat} <properties> <spring.version>3.1.0.RC1</spring.version> <spring.data.jpa.version>1.1.0.M1</spring.data.jpa.version> <querydsl.version>2.2.3</querydsl.version> </properties> {noformat} Thanks.
    via by Mark Serrano,
  • I have a Jpa repository that utilizes QueryDSL's fluent API: {code:title=IUserRepository.java|borderStyle=solid} public interface IUserRepository extends JpaRepository<User, Long>, QueryDslPredicateExecutor<User> {code} Then I have a service that reads records from the repository via the findAll() method. I have a requirement that the fields must be dynamic and the records are pageable: {code:title=UserService.java|borderStyle=solid} @Service @Transactional public class UserService implements IUserService { @Autowired private IUserRepository userRepository; @Autowired private EntityManagerFactory emf; @Override public Page<User> readFromRepository(String username, Pageable page) { PathBuilder<User> entityPath = new PathBuilder<User>(User.class, "user"); StringPath path = entityPath.get(new StringPath("username")); BooleanExpression hasUsername = path.eq(username); BooleanBuilder builder = new BooleanBuilder(); builder.and(hasUsername); return userRepository.findAll(builder, page); } ... } {code} However an exception is thrown whenever that method is called: {noformat} java.lang.NoSuchMethodError: com.mysema.query.jpa.JPQLQuery.offset(J)Lcom/mysema/query/Query; at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.applyPagination(QueryDslJpaRepository.java:168) at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.findAll(QueryDslJpaRepository.java:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:322) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:307) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy24.findAll(Unknown Source) at org.demo.service.UserService.readFromRepository(UserService.java:43) {noformat} I tried digging into the code and the source and I can't find the reasons why. The internal implementation doesn't show any missing methods. I have checked my jars but I didn't find any old dependencies. I tested my project both at home and at work (Ubuntu, Windows, proxied, non-proxied environments). But I keep getting the same exception. When I check the following: {noformat} org.springframework.data.jpa.repository.support.QueryDslJpaRepository.applyPagination(QueryDslJpaRepository.java:168) {noformat} {code:title=QueryDslJpaRepository.java|borderStyle=solid} protected JPQLQuery applyPagination(JPQLQuery query, Pageable pageable) { if (pageable == null) { return query; } query.offset(pageable.getOffset()); query.limit(pageable.getPageSize()); return applySorting(query, pageable.getSort()); } {code} As a workaround, I did the following code: {code:title=UserService.java|borderStyle=solid} @Service @Transactional public class UserService implements IUserService { @Autowired private IUserRepository userRepository; @Autowired private EntityManagerFactory emf; ... @Override public List<User> readFromEntityManager(String username, Pageable page) { PathBuilder<User> entityPath = new PathBuilder<User>(User.class, "user"); StringPath path = entityPath.get(new StringPath("username")); BooleanExpression hasUsername = path.ne(username); BooleanBuilder builder = new BooleanBuilder(); builder.and(hasUsername); EntityManager em = emf.createEntityManager(); JPQLQuery result = new JPAQuery(em).from(entityPath).where(builder); if (page != null) { result.offset(page.getOffset()); result.limit(page.getPageSize()); } return result.list(entityPath); } ... } {code} And it works perfectly. I tried to match as possible the original Spring JPA implementation. I don't really know what's wrong with the findAll() method, but directly calling the EntityManagerFactory somehow did the trick. I have attached a strip-down version of my webapp. It's a Maven project with unit tests included. Just run Maven test to verify the error. You need to have MySQL and create a db "testdb". No data is needed but you can prepopulate them. There's a data.sql inside the classpath. (I'm trying to initialize the db with jdbc:initialize-database but it keeps throwing an error. You might wanna take a peek of that error if you like). By the way my Maven properties: {noformat} <properties> <spring.version>3.1.0.RC1</spring.version> <spring.data.jpa.version>1.1.0.M1</spring.data.jpa.version> <querydsl.version>2.2.3</querydsl.version> </properties> {noformat} Thanks.
    via by Mark Serrano,
  • When using QueryDSL 3.0.0 my testcase is broken at run-time: {code} java.lang.NoSuchMethodError: com.mysema.query.jpa.JPQLQuery.from([Lcom/mysema/query/types/EntityPath;)Lcom/mysema/query/jpa/JPQLCommonQuery; at org.springframework.data.jpa.repository.support.Querydsl.createQuery(Querydsl.java:88) at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.createQuery(QueryDslJpaRepository.java:131) at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.findAll(QueryDslJpaRepository.java:93) at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.findAll(QueryDslJpaRepository.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:333) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:318) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy97.findAll(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198) at com.sun.proxy.$Proxy98.findAll(Unknown Source) {code}
    via by Thomas Hackel,
  • When using QueryDSL 3.0.0 my testcase is broken at run-time: {code} java.lang.NoSuchMethodError: com.mysema.query.jpa.JPQLQuery.from([Lcom/mysema/query/types/EntityPath;)Lcom/mysema/query/jpa/JPQLCommonQuery; at org.springframework.data.jpa.repository.support.Querydsl.createQuery(Querydsl.java:88) at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.createQuery(QueryDslJpaRepository.java:131) at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.findAll(QueryDslJpaRepository.java:93) at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.findAll(QueryDslJpaRepository.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:333) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:318) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy97.findAll(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198) at com.sun.proxy.$Proxy98.findAll(Unknown Source) {code}
    via by Thomas Hackel,
    • java.lang.NoSuchMethodError: com.mysema.query.jpa.JPQLQuery.offset(J)Lcom/mysema/query/Query; at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.applyPagination(QueryDslJpaRepository.java:168) at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.findAll(QueryDslJpaRepository.java:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:322) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:307) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy24.findAll(Unknown Source) at org.demo.service.UserService.readFromRepository(UserService.java:43)

    Users with the same issue

    Unknown visitor1 times, last one,