-1

Here is my JPA query:

String jpql = "SELECT a FROM Account a WHERE a.id IN :list";
TypedQuery<Account> q = mgr.createQuery(jpql, Account.class);
q.setParameter("list", list);
return q.getResultList();

Here is the error log:

Cannot find type of (part of) a.id since symbol has no type; implicit variable?
org.datanucleus.exceptions.NucleusUserException: Cannot find type of (part of) a.id since symbol has no type; implicit variable?
    at org.datanucleus.query.expression.PrimaryExpression.bind(PrimaryExpression.java:274)
    at org.datanucleus.query.expression.DyadicExpression.bind(DyadicExpression.java:87)
    at org.datanucleus.query.compiler.JavaQueryCompiler.compileFilter(JavaQueryCompiler.java:480)
    at org.datanucleus.query.compiler.JPQLCompiler.compile(JPQLCompiler.java:81)
    at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:271)
    at org.datanucleus.store.query.Query.setImplicitParameter(Query.java:799)
    at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:437)
    at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:57)
    at com.example.game.dao.impl.AccountDaoImpl.findByIds(AccountDaoImpl.java:42)
    at com.example.game.gameApi.sendPuzzle(gameApi.java:123)
    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 com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:304)
    at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:161)
    at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:120)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    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 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.DevAppServerServersFilter.doFilter(DevAppServerServersFilter.java:106)
    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.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:421)
    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.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    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)

Also, account looks like this

@Entity
public class Account implements java.io.Serializable{
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;

    private String name;


    public Account(long id, name) {
        super();
        Key key = KeyFactory.createKey(Account.class.getSimpleName(), id);
        this.key = key;
           this.name = name
    }

//getters and setters

}

For a counterpart, in python the datastore supports multi key queries similar to

list_of_keys = ndb.put_multi(list_of_entities)
list_of_entities = ndb.get_multi(list_of_keys)
ndb.delete_multi(list_of_keys)

And as suggested by the tutorial, using a loop would be inefficient.

RedBrogdon
  • 5,113
  • 2
  • 24
  • 31
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • 1
    I show my query, I show my log, I show my model, and I show how it can be done in another language (python). So I really hope I get some help here. (I am not here to get up-votes or down-votes -- just help). – Katedral Pillon Apr 09 '13 at 15:44
  • datastore does not accept `IN` queries. I tried and that is the error I got from app engine. You should try it. I asked the question a while back so I don't know what might have changed. But I recall trying `IN` questions and having an error returned. – Katedral Pillon Sep 03 '14 at 16:35
  • JPA perfectly supports IN queries with any Collections value (not arrays). Your problem is that you use `a.id` instead of `a.key`. Anyway, the answer you marked as accepted does absolutely not answer your question, so it should not be marked as such. This is even more true when there is an actual correct and valuable answer which should be accepted. – Guillaume Polet Sep 04 '14 at 23:30

2 Answers2

1

I think you want your query to be:

String jpql = "SELECT a FROM Account a WHERE a.key IN :list";

since the variable is named key, not id.

Bjorn Roche
  • 11,279
  • 6
  • 36
  • 58
-2

I don't know if JPA allows for what you are seeking, but you can definitely do it using a DatastoreService object, as in

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

From there, you can use your python app-engine knowledge to guide you. If you have been developing for long, then you have probably had to use Hibernate to supplement JPA. If you really want to code to the interface, then you may not like this answer. But it is a solution no different than using Hibernate.

Konsol Labapen
  • 2,424
  • 2
  • 15
  • 12
  • 2
    Ahh, so you're not answering his question then (using your rationale), the same that you downvoted that other answer for (before its author deleted it). He asked how do I do this in JPA. Hello pot, kettle here – Neil Stockton Apr 10 '13 at 06:21