java - 'gomobile.user u' cannot be the first declaration of the FROM clause -
i'm trying query data of user
table in schema gomobile
of derbydb.
i've established connection database , created jpa entity, columns corresponding database table.
@entity @table(name = "user", schema = "gomobile") public class user implements serializable { private static final long serialversionuid = 1l; // columns public static list<user> getall() { string querystring = "select u gomobile.user u"; entitymanager em = persistence.createentitymanagerfactory("eclipselink").createentitymanager(); return em.createquery(querystring, user.class).getresultlist(); } }
this stracktrace:
exception in thread "main" java.lang.illegalargumentexception: exception occurred while creating query in entitymanager: exception description: problem compiling [select u gomobile.user u]. [14, 41] 'gomobile.user u' cannot first declaration of clause. @ org.eclipse.persistence.internal.jpa.entitymanagerimpl.createquery(entitymanagerimpl.java:1605) @ org.eclipse.persistence.internal.jpa.entitymanagerimpl.createquery(entitymanagerimpl.java:1625) @ com.sap.sapchat.jpa.entities.user.getall(user.java:45) @ com.sap.sapchat.jpa.entities.initdatabase.main(initdatabase.java:50) caused by: exception [eclipselink-0] (eclipse persistence services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.jpqlexception exception description: problem compiling [select u gomobile.user u]. [14, 41] 'gomobile.user u' cannot first declaration of clause. @ org.eclipse.persistence.internal.jpa.jpql.hermesparser.buildexception(hermesparser.java:155) @ org.eclipse.persistence.internal.jpa.jpql.hermesparser.validate(hermesparser.java:347) @ org.eclipse.persistence.internal.jpa.jpql.hermesparser.populatequeryimp(hermesparser.java:278) @ org.eclipse.persistence.internal.jpa.jpql.hermesparser.buildquery(hermesparser.java:163) @ org.eclipse.persistence.internal.jpa.ejbqueryimpl.buildejbqldatabasequery(ejbqueryimpl.java:142) @ org.eclipse.persistence.internal.jpa.ejbqueryimpl.buildejbqldatabasequery(ejbqueryimpl.java:116) @ org.eclipse.persistence.internal.jpa.ejbqueryimpl.<init>(ejbqueryimpl.java:102) @ org.eclipse.persistence.internal.jpa.ejbqueryimpl.<init>(ejbqueryimpl.java:86) @ org.eclipse.persistence.internal.jpa.entitymanagerimpl.createquery(entitymanagerimpl.java:1603) ... 3 more
my persistence declaration in persistence.xml looks this:
<persistence-unit name="eclipselink" transaction-type="resource_local"> <class>jpa.entities.user</class> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/gomobile;create=true" /> <property name="javax.persistence.jdbc.user" value="gomobile" /> <property name="javax.persistence.jdbc.password" value="mypassword" /> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.clientdriver" /> </properties> </persistence-unit>
edit
if use:
string querystring = "select * gomobile.user u";
i error:
exception in thread "main" java.lang.illegalargumentexception: exception occurred while creating query in entitymanager: exception description: syntax error parsing [select * gomobile.user u]. [38, 38] select statement must have clause. [7, 7] left expression missing arithmetic expression. [9, 38] right expression not arithmetic expression. @ org.eclipse.persistence.internal.jpa.entitymanagerimpl.createquery(entitymanagerimpl.java:1605) @ org.eclipse.persistence.internal.jpa.entitymanagerimpl.createquery(entitymanagerimpl.java:1625) @ com.sap.sapchat.jpa.entities.user.getall(user.java:75) @ com.sap.sapchat.jpa.entities.initdatabase.main(initdatabase.java:64) caused by: exception [eclipselink-0] (eclipse persistence services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.jpqlexception exception description: syntax error parsing [select * gomobile.user u]. [38, 38] select statement must have clause. [7, 7] left expression missing arithmetic expression. [9, 38] right expression not arithmetic expression. @ org.eclipse.persistence.internal.jpa.jpql.hermesparser.buildexception(hermesparser.java:155) @ org.eclipse.persistence.internal.jpa.jpql.hermesparser.validate(hermesparser.java:334) @ org.eclipse.persistence.internal.jpa.jpql.hermesparser.populatequeryimp(hermesparser.java:278) @ org.eclipse.persistence.internal.jpa.jpql.hermesparser.buildquery(hermesparser.java:163) @ org.eclipse.persistence.internal.jpa.ejbqueryimpl.buildejbqldatabasequery(ejbqueryimpl.java:142) @ org.eclipse.persistence.internal.jpa.ejbqueryimpl.buildejbqldatabasequery(ejbqueryimpl.java:116) @ org.eclipse.persistence.internal.jpa.ejbqueryimpl.<init>(ejbqueryimpl.java:102) @ org.eclipse.persistence.internal.jpa.ejbqueryimpl.<init>(ejbqueryimpl.java:86) @ org.eclipse.persistence.internal.jpa.entitymanagerimpl.createquery(entitymanagerimpl.java:1603) ... 3 more
there no entity called gomobile.user, cannot use in jpql queries. jpql object based, , not use tables/schema , fields directly in sql.
you should using "select u user u", entity quering named "user" default.
Comments
Post a Comment