New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.8.1] QueryDSL JPA on AppEngine not working because of escape character #262

Closed
marceloverdijk opened this Issue Oct 31, 2012 · 28 comments

Comments

Projects
None yet
2 participants
@marceloverdijk

I tried to get querydsl working on AppEngine today. I'm using querydsl via the Spring Data JPA repository support.

As soon as I try to run querydsl filter containing a 'startsWith' I get the below exception.
When I use dynamic query methods or Spring Data Specifications I don't run in this issue.

org.springframework.orm.jpa.JpaSystemException: Problem with query <SELECT FROM User user WHERE user.username like ?1 escape '!' ORDER BY user.username asc>: GAE doesn't currently support ESCAPE syntax (Literal{!}); nested exception is javax.persistence.PersistenceException: Problem with query <SELECT FROM User user WHERE user.username like ?1 escape '!' ORDER BY user.username asc>: GAE doesn't currently support ESCAPE syntax (Literal{!})
    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:326)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:91)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    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.zeroturnaround.javarebel.integration.util.ReloadingProxyFactory$ReloadingMethodHandler.invoke(JRebel:73)
    at nl.valid.minerva.web.UserController.list(UserController.java:45)
    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 com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:757)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:698)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:911)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:807)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:792)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.__handle(ContextHandler.java:765)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:383)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: javax.persistence.PersistenceException: Problem with query <SELECT FROM User user WHERE user.username like ?1 escape '!' ORDER BY user.username asc>: GAE doesn't currently support ESCAPE syntax (Literal{!})
    at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:302)
    at org.datanucleus.api.jpa.JPAQuery.getResultList(JPAQuery.java:202)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.getResultList(AbstractJPAQuery.java:221)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:273)
    at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.findAll(QueryDslJpaRepository.java:113)
    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 com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:334)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:319)
    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)
    ... 100 more
Caused by: com.google.appengine.datanucleus.query.DatastoreQuery$UnsupportedDatastoreFeatureException: Problem with query <SELECT FROM User user WHERE user.username like ?1 escape '!' ORDER BY user.username asc>: GAE doesn't currently support ESCAPE syntax (Literal{!})
    at com.google.appengine.datanucleus.query.DatastoreQuery.handleMatchesOperation(DatastoreQuery.java:837)
    at com.google.appengine.datanucleus.query.DatastoreQuery.addExpression(DatastoreQuery.java:816)
    at com.google.appengine.datanucleus.query.DatastoreQuery.addFilters(DatastoreQuery.java:721)
    at com.google.appengine.datanucleus.query.DatastoreQuery.compile(DatastoreQuery.java:247)
    at com.google.appengine.datanucleus.query.JPQLQuery.performExecute(JPQLQuery.java:170)
    at org.datanucleus.store.query.Query.executeQuery(Query.java:1789)
    at org.datanucleus.store.query.Query.executeWithMap(Query.java:1693)
    at org.datanucleus.api.jpa.JPAQuery.getResultList(JPAQuery.java:185)
    ... 114 more
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 31, 2012

Member

Like with escape is defined in the standard, but I will add a Appengine dialect with autodetection to Querydsl JPA.

Member

timowest commented Oct 31, 2012

Like with escape is defined in the standard, but I will add a Appengine dialect with autodetection to Querydsl JPA.

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Oct 31, 2012

That would be great!

That would be great!

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 31, 2012

Member

Could you try the snapshot version 2.8.2.BUILD-SNAPSHOT? You can get it via this repository https://oss.sonatype.org/content/repositories/snapshots/

Member

timowest commented Oct 31, 2012

Could you try the snapshot version 2.8.2.BUILD-SNAPSHOT? You can get it via this repository https://oss.sonatype.org/content/repositories/snapshots/

timowest added a commit that referenced this issue Oct 31, 2012

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Oct 31, 2012

I tried with the 2.8.2.BUILD-SNAPSHOT but encounter the same issue.
I'm trying to to find out if the change is picked up or not.

I tried with the 2.8.2.BUILD-SNAPSHOT but encounter the same issue.
I'm trying to to find out if the change is picked up or not.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 31, 2012

Member

Ok, this might also be an issue with the datanucleus JPA autodetection. What is the class returned by entityManager.getDelegate()?

Querydsl uses this class to detect the JPA provider.

Member

timowest commented Oct 31, 2012

Ok, this might also be an issue with the datanucleus JPA autodetection. What is the class returned by entityManager.getDelegate()?

Querydsl uses this class to detect the JPA provider.

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Oct 31, 2012

org.datanucleus.ObjectManagerImpl

org.datanucleus.ObjectManagerImpl

timowest added a commit that referenced this issue Oct 31, 2012

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Oct 31, 2012

I just tried again (not sure if snapshot was build already) but if still failed.
In your commit I see you used org.datanucleus.ObjectManager but I think this should be org.datanucleus.ObjectManagerImpl.
Note the Impl at the end.

I just tried again (not sure if snapshot was build already) but if still failed.
In your commit I see you used org.datanucleus.ObjectManager but I think this should be org.datanucleus.ObjectManagerImpl.
Note the Impl at the end.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 31, 2012

Member

ObjectManager is a superinterface (http://www.datanucleus.org/javadocs/core/3.0/org/datanucleus/ObjectManager.html), so I guess a safer choice.

I will let you know when a new snapshot is available.

Member

timowest commented Oct 31, 2012

ObjectManager is a superinterface (http://www.datanucleus.org/javadocs/core/3.0/org/datanucleus/ObjectManager.html), so I guess a safer choice.

I will let you know when a new snapshot is available.

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Oct 31, 2012

Yes probably your are right. Don't know the internals.

Yes probably your are right. Don't know the internals.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 31, 2012

Member

Now it seems to be available.

Member

timowest commented Oct 31, 2012

Now it seems to be available.

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Oct 31, 2012

Yes I got the code (checking on org.datanucleus.ObjectManager) but I unfortunately see the same error.
It took me a little bit longer to respond as I wanted to double check.

Yes I got the code (checking on org.datanucleus.ObjectManager) but I unfortunately see the same error.
It took me a little bit longer to respond as I wanted to double check.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 31, 2012

Member

Could you inject DataNucleusTemplates.DEFAULT directly into your query? If that still doesn't work I will look tomorrow what went wrong.

Member

timowest commented Oct 31, 2012

Could you inject DataNucleusTemplates.DEFAULT directly into your query? If that still doesn't work I will look tomorrow what went wrong.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 31, 2012

Member

It's the following constructor

JPAQuery(javax.persistence.EntityManager em, JPQLTemplates patterns) 

I want to know if there are still issues with the autodetection or something else.

Member

timowest commented Oct 31, 2012

It's the following constructor

JPAQuery(javax.persistence.EntityManager em, JPQLTemplates patterns) 

I want to know if there are still issues with the autodetection or something else.

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Oct 31, 2012

Hmm, while debugging I noticed the
Class.forName("org.datanucleus.ObjectManager") gives: An exception occurred: java.lang.ClassNotFoundException.

Class.forName("org.datanucleus.ObjectManagerImpl") does return a Class.

Hmm, while debugging I noticed the
Class.forName("org.datanucleus.ObjectManager") gives: An exception occurred: java.lang.ClassNotFoundException.

Class.forName("org.datanucleus.ObjectManagerImpl") does return a Class.

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Oct 31, 2012

Aha this changed from DataNucleus 3.0 to 3.1
http://www.datanucleus.org/javadocs/core/3.0/org/datanucleus/ObjectManagerImpl.html this one implements ObjectManager
and
http://www.datanucleus.org/javadocs/core/3.1/org/datanucleus/ObjectManagerImpl.html does implement ExecutionContext and TransactionEventListener (which both do not implement ObjectManager).

Why http://www.datanucleus.org/javadocs/core/3.1/org/datanucleus/ObjectManager.html is mentioning that the ObjectManagerImpl is a known implementing class I don't know.

Maybe safe to add both ObjectManager and ObjectManagerImpl to the mapping?

Aha this changed from DataNucleus 3.0 to 3.1
http://www.datanucleus.org/javadocs/core/3.0/org/datanucleus/ObjectManagerImpl.html this one implements ObjectManager
and
http://www.datanucleus.org/javadocs/core/3.1/org/datanucleus/ObjectManagerImpl.html does implement ExecutionContext and TransactionEventListener (which both do not implement ObjectManager).

Why http://www.datanucleus.org/javadocs/core/3.1/org/datanucleus/ObjectManager.html is mentioning that the ObjectManagerImpl is a known implementing class I don't know.

Maybe safe to add both ObjectManager and ObjectManagerImpl to the mapping?

timowest added a commit that referenced this issue Oct 31, 2012

timowest added a commit that referenced this issue Oct 31, 2012

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 31, 2012

Member

Done that now. Try again.

Member

timowest commented Oct 31, 2012

Done that now. Try again.

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Oct 31, 2012

To bad still not working. Need to look into this tomorrow again.

It seems with latest code that mappings until
addMapping("org.datanucleus.ObjectManager", DataNucleusTemplates.DEFAULT);
are not added (due to ClassNotFoundException).
But when trying to add addMapping("org.datanucleus.ObjectManager", DataNucleusTemplates.DEFAULT); the debugger gets into the internal Class.forName stuff and the ultimately returns to

public JPAQuery(EntityManager em) {
    super(em, JPAProvider.getTemplates(em), new DefaultQueryMetadata());
}

in JPAQuery.class.

But I never see addMapping("org.datanucleus.ObjectManagerImpl", DataNucleusTemplates.DEFAULT); being called.

Also checking JPAProvider.mappings as expression in debug session tells me the size of the mappings is 0.

To bad still not working. Need to look into this tomorrow again.

It seems with latest code that mappings until
addMapping("org.datanucleus.ObjectManager", DataNucleusTemplates.DEFAULT);
are not added (due to ClassNotFoundException).
But when trying to add addMapping("org.datanucleus.ObjectManager", DataNucleusTemplates.DEFAULT); the debugger gets into the internal Class.forName stuff and the ultimately returns to

public JPAQuery(EntityManager em) {
    super(em, JPAProvider.getTemplates(em), new DefaultQueryMetadata());
}

in JPAQuery.class.

But I never see addMapping("org.datanucleus.ObjectManagerImpl", DataNucleusTemplates.DEFAULT); being called.

Also checking JPAProvider.mappings as expression in debug session tells me the size of the mappings is 0.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 1, 2012

Member

Ok, weird. I will also see later why it fails. I just looked at the code and it should be correct. Btw, ObjectManagerImpl might be a hidden class? Maybe that's why it fails.

So the Class.forName(...) calls work if exected manually?

Member

timowest commented Nov 1, 2012

Ok, weird. I will also see later why it fails. I just looked at the code and it should be correct. Btw, ObjectManagerImpl might be a hidden class? Maybe that's why it fails.

So the Class.forName(...) calls work if exected manually?

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Nov 1, 2012

I just tried constructing a JPAQuery with the DataNucleusTemplates.DEFAULT manually.

QUser user = QUser.user;
JPQLQuery q = new JPAQuery(em, DataNucleusTemplates.DEFAULT);
q.from(user).where(user.username.startsWith("ad"));
User u = q.singleResult(user);

This is (I assume) similar as userRepository.findAll(QUser.user.username.startsWith(q), pageable); only without the paging.

And that worked, it returned a user without any exception.
So at least I think that proves the DataNucleusTemplates is working.

Now only we need to find why the detection is not working and what is going wrong there.
Maybe you have a clue from my previous comment?

I just tried constructing a JPAQuery with the DataNucleusTemplates.DEFAULT manually.

QUser user = QUser.user;
JPQLQuery q = new JPAQuery(em, DataNucleusTemplates.DEFAULT);
q.from(user).where(user.username.startsWith("ad"));
User u = q.singleResult(user);

This is (I assume) similar as userRepository.findAll(QUser.user.username.startsWith(q), pageable); only without the paging.

And that worked, it returned a user without any exception.
So at least I think that proves the DataNucleusTemplates is working.

Now only we need to find why the detection is not working and what is going wrong there.
Maybe you have a clue from my previous comment?

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Nov 1, 2012

I think it's really related to this call:

addMapping("org.datanucleus.ObjectManager", DataNucleusTemplates.DEFAULT);

While debugging I can see it go into the Class.forName which is not happening for the previous defines mappings.

And then I end up at

public JPAQuery(EntityManager em) {
        super(em, JPAProvider.getTemplates(em), new DefaultQueryMetadata());
}

skipping the mappings.put(Class.forName(className), templates); call for org.datanucleus.ObjectManagerImpl.

Hmm, maybe the Class.forName for org.datanucleus.ObjectManager is causing another exception then ClassNotFoundException (the only one being catched), which would cause the remainder of the static code (and hence the mapping for org.datanucleus.ObjectManagerImpl not being called anymore?

Maybe good to just catch Exception instead of ClassNotFoundException?

I think it's really related to this call:

addMapping("org.datanucleus.ObjectManager", DataNucleusTemplates.DEFAULT);

While debugging I can see it go into the Class.forName which is not happening for the previous defines mappings.

And then I end up at

public JPAQuery(EntityManager em) {
        super(em, JPAProvider.getTemplates(em), new DefaultQueryMetadata());
}

skipping the mappings.put(Class.forName(className), templates); call for org.datanucleus.ObjectManagerImpl.

Hmm, maybe the Class.forName for org.datanucleus.ObjectManager is causing another exception then ClassNotFoundException (the only one being catched), which would cause the remainder of the static code (and hence the mapping for org.datanucleus.ObjectManagerImpl not being called anymore?

Maybe good to just catch Exception instead of ClassNotFoundException?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 1, 2012

Member

I will catch all Exceptions, good idea.

Member

timowest commented Nov 1, 2012

I will catch all Exceptions, good idea.

timowest added a commit that referenced this issue Nov 1, 2012

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Nov 1, 2012

Pls let me know when snapshot is ready then I will test again.

Pls let me know when snapshot is ready then I will test again.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 1, 2012

Member

Now you could test again.

Member

timowest commented Nov 1, 2012

Now you could test again.

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Nov 1, 2012

I tried but no difference. While debugging I can see the code now contains the Exception catch instead of ClassNotFoundException.

But the behaviour I see is the same.
For adding the mappings before org.datanucleus.ObjectManager the addMapping method returns without adding a mapping.

As soon as it tries to do Class.forName("org.datanucleus.ObjectManager") the debugger goes into the Class.forName method which I cannot further debug.
Next thing I see is that it returns to:

public JPAQuery(EntityManager em) {
    super(em, JPAProvider.getTemplates(em), new DefaultQueryMetadata());
}

So without even trying to add mapping for org.datanucleus.ObjectManagerImpl.
At that point the size of the JPAProvider.mappings map is 0.

I tried but no difference. While debugging I can see the code now contains the Exception catch instead of ClassNotFoundException.

But the behaviour I see is the same.
For adding the mappings before org.datanucleus.ObjectManager the addMapping method returns without adding a mapping.

As soon as it tries to do Class.forName("org.datanucleus.ObjectManager") the debugger goes into the Class.forName method which I cannot further debug.
Next thing I see is that it returns to:

public JPAQuery(EntityManager em) {
    super(em, JPAProvider.getTemplates(em), new DefaultQueryMetadata());
}

So without even trying to add mapping for org.datanucleus.ObjectManagerImpl.
At that point the size of the JPAProvider.mappings map is 0.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 1, 2012

Member

Ok, but did you try the Class.forName calls yourself?

Member

timowest commented Nov 1, 2012

Ok, but did you try the Class.forName calls yourself?

@marceloverdijk

This comment has been minimized.

Show comment
Hide comment
@marceloverdijk

marceloverdijk Nov 1, 2012

Good point, should have thought about that myself...

I copied al the code of the JPAProvider class to my own class (a Spring MVC Controller in this case).
And the weird thing... it just works I get back the com.mysema.query.jpa.DataNucleusTemplates :-)

Even from the same controller I call JPAProvider.getTempalte(with the same em) but I get back the

So maybe my querydsl jar was out of sync with the sources jar?
That could explain why I never saw the ObjectManagerImpl being called...

So I removed the .cache form .m2/repository folder togther with com/mysema to make sure everything was ok.

And then it worked.

I was always using mvn with -U option to force a check for updated releases and snapshots on remote repositories but didn't seem to work...

I'm glad this is working nog.
Thanks for your patience and quick fix. Look forward to see this in stable release.

Cheers,
Marcel

Good point, should have thought about that myself...

I copied al the code of the JPAProvider class to my own class (a Spring MVC Controller in this case).
And the weird thing... it just works I get back the com.mysema.query.jpa.DataNucleusTemplates :-)

Even from the same controller I call JPAProvider.getTempalte(with the same em) but I get back the

So maybe my querydsl jar was out of sync with the sources jar?
That could explain why I never saw the ObjectManagerImpl being called...

So I removed the .cache form .m2/repository folder togther with com/mysema to make sure everything was ok.

And then it worked.

I was always using mvn with -U option to force a check for updated releases and snapshots on remote repositories but didn't seem to work...

I'm glad this is working nog.
Thanks for your patience and quick fix. Look forward to see this in stable release.

Cheers,
Marcel

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 1, 2012

Member

Yes, that's always the problem with snapshots. But great we got this working.

Cheers,
Timo

Member

timowest commented Nov 1, 2012

Yes, that's always the problem with snapshots. But great we got this working.

Cheers,
Timo

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 19, 2012

Member

Released in 2.9.0

Member

timowest commented Nov 19, 2012

Released in 2.9.0

@timowest timowest closed this Nov 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment