surinder-insonix / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

Support JDOQL/JPQL setResultClass #166

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
i want to set query result to another bean by using setResultClass,
but always get ClassCastException,here is my code

public User getUserByNameAndPwd(String userName, String password) {
        PersistenceManager pm = pmf.getPersistenceManager();
        Query query = pm.newQuery("select from com.grids.sfa.entity.Person where"
                        + " password==paramPassword && firstName == paramFirstName");
        query.declareParameters("String paramPassword,String paramFirstName ");
        query.setResult("firstName,password");

        query.setResultClass(com.grids.sfa.users.vo.User.class);

        List results = null;
        try {

            results = (List) query.execute(password, userName);

        } finally {
            query.closeAll();
        }

        if (results.size() > 0) {
             Object[] obj=(Object[])results.get(0);
             System.out.println(obj[0]);
             System.out.println(obj[1]);
             User user = (User)results.get(0);
            return  user;
        } else {
            return new User();
        }
    }

package com.grids.sfa.users.vo;

import com.google.appengine.api.datastore.Key;

public class User {

    private String firstName;
    private String lastName;
    private String password;
    private String repassword;
    private Key key;

    public User() {

    }

    public User(String firstName) {
        this.firstName = firstName;

    }

    public User(String firstName, String password) {
        this.firstName = firstName;
        this.password = password;
    }

    public User(String firstName, String password, String repassword,
            String lastName) {
        this.firstName = firstName;
        this.password = password;
    }

    public Key getKey() {
        return key;
    }

    public void setKey(Key key) {
        this.key = key;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRepassword() {
        return repassword;
    }

    public void setRepassword(String repassword) {
        this.repassword = repassword;
    }
}

print out in the console ::::::
21232f297a57a5a743894a0e4a801fc3
admin
21232f297a57a5a743894a0e4a801fc3

error msg:

[Ljava.lang.Object; cannot be cast to com.grids.sfa.users.vo.User

RequestURI=/users/login_login.action
Caused by:

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
com.grids.sfa.users.vo.User
    at
com.grids.sfa.users.dao.impl.LoginDaoImpl.getUserByNameAndPwd(LoginDaoImpl.java:
37)
    at
com.grids.sfa.users.service.impl.LoginServiceImpl.getUserByNameAndPwd(LoginServi
ceImpl.java:52)
    at com.grids.sfa.users.action.LoginAction.login(LoginAction.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java
:100)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvoca
tion.java:441)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionIn
vocation.java:280)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:243)
    at
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(Defau
ltWorkflowInterceptor.java:165)
    at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilt
erInterceptor.java:87)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationIn
terceptor.java:252)
    at
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doInte
rcept(AnnotationValidationInterceptor.java:68)
    at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilt
erInterceptor.java:87)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(Convers
ionErrorInterceptor.java:122)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(Parameters
Interceptor.java:195)
    at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilt
erInterceptor.java:87)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(Parameters
Interceptor.java:195)
    at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilt
erInterceptor.java:87)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(Static
ParametersInterceptor.java:179)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInter
ceptor.java:75)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor
.java:94)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterce
ptor.java:235)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDriven
Interceptor.java:89)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(Scope
dModelDrivenInterceptor.java:130)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(Debuggin
gInterceptor.java:267)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterc
eptor.java:126)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterc
eptor.java:138)
    at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilt
erInterceptor.java:87)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.ja
va:165)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigI
nterceptor.java:164)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.
java:179)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(Except
ionMappingInterceptor.java:176)
    at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.j
ava:237)
    at
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
    at
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:39
5)
    at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.jav
a:1084)
    at
com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.jav
a:129)
    at
com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.jav
a:1084)
    at
org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp
.java:102)
    at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.jav
a:1084)
    at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(Transactio
nCleanupFilter.java:43)
    at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.jav
a:1084)
    at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilte
r.java:121)
    at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.jav
a:1084)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineW
ebAppContext.java:54)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
    at
com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.han
dle(JettyContainerService.java:342)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
    at org.mortbay.jetty.Server.handle(Server.java:313)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
    at
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
    at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
    at
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)

What version of the product are you using? On what operating system?
appengine sdk 1.2.6
datanucleus-appengine-1.0.3
datanucleus-core-1.1.5
jdo-api-2.3-eb
windows xp

Please provide any additional information below.

can appengine support setResultClass??

Original issue reported on code.google.com by wowost...@gmail.com on 27 Nov 2009 at 3:10

GoogleCodeExporter commented 8 years ago
Thanks for the report.  This is currently unimplemented for App Engine but 
shouldn't
be too hard to take care of.

Original comment by max.r...@gmail.com on 27 Nov 2009 at 11:30

GoogleCodeExporter commented 8 years ago
Please fix this. 

Original comment by other...@gmail.com on 17 Dec 2009 at 5:09

GoogleCodeExporter commented 8 years ago
Same error occurred to me... Assumed the setResultClass API is implemented but 
ran
into this exception and stuck for a while.  Could you at least publish what is 
the
*implemented* subset of JDO APIs in app engine so that we don't waste our time 
trying
the debugging the non-supported functions ?

Thanks,

Original comment by zhu.r...@gmail.com on 26 Mar 2010 at 5:55

GoogleCodeExporter commented 8 years ago

Original comment by googleco...@yahoo.co.uk on 15 Jul 2011 at 6:43

GoogleCodeExporter commented 8 years ago

Original comment by googleco...@yahoo.co.uk on 11 Aug 2011 at 1:27

GoogleCodeExporter commented 8 years ago
SVN trunk now supports this for the typical types of result class found in 
JDOQL, JPQL

Original comment by googleco...@yahoo.co.uk on 11 Aug 2011 at 2:13