You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Griffiths Guy <Gu...@thalesgroup.com> on 2007/08/15 15:35:13 UTC

Querying a Primary Key

Hi,
I am writing an application which requires me to query an auto-generated
Primary Key, but I am currently getting a "Can't resolve path component"
error.

Basically, my application has a table of generated Events, with a
database-generated PK in the column EVENT_ID.  Using the Cayenne Modeler I
have not made this visible, but I have added this method: 

    public Long getEventID() {
       return (getObjectId() != null &&
    		   !getObjectId().isTemporary())
                            ?
 
(Long)getObjectId().getIdSnapshot().get(EVENT_ID_PK_COLUMN)
                            : null;
    }

to the EventsDB class (i.e. the non-auto-generated one).  I based this on
the method here:
http://cayenne.apache.org/doc20/accessing-pk-and-fk-values.html

I need the end user to be able to obtain all rows from the Events table
since a specified event.  They will know the EventID of the last event they
obtained from the above method.

To do this, I am using a select query with the following qualifier:

ExpressionFactory.greaterExp(EventsDB.EVENT_ID_PK_COLUMN, since);
    	
Where "since" is a Long which is set to the value of the previous known
EventID.

However, when I try and perform this query, I get the error:
Can't resolve path component: [EventsDB.EVENT_ID]

The auto-generated _EventsDB.java has defined EventsDB.EVENT_ID_PK_COLUMN as
public static final String EVENT_ID_PK_COLUMN = "EVENT_ID";

The PK column name is of course EVENT_ID.

I would be very grateful if anyone could suggest what is going wrong and how
to remedy it, or a possible workaround.  I have tried making the EVENT_ID
column correspond to an object in the Cayenne Modeler (despite the warning
it throws up), and using EventsDB.EVENT_ID_PROPERTY in the query, but this
gives near identical errors.  I have also tried rebuilding the database etc.

I am using Cayenne v2.0.3 and I have included the full stack trace as a
footer to this message.

Thanks in advance for any help anyone can provide.

Guy Griffiths

-- 
org.apache.cayenne.CayenneRuntimeException: [v.2.0.3 May 6 2007] Query
exception.
	at
org.apache.cayenne.access.DataDomainQueryAction.nextQueryException(DataDomai
nQueryAction.java:428)
	at
org.apache.cayenne.access.DataNode.performQueries(DataNode.java:280)
	at
org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryActi
on.java:301)
	at
org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAc
tion.java:60)
	at
org.apache.cayenne.access.DataDomainQueryAction$1.transform(DataDomainQueryA
ction.java:273)
	at
org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:836)
	at
org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDo
mainQueryAction.java:270)
	at
org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryActio
n.java:110)
	at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:746)
	at
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQuery
Action.java:217)
	at
org.apache.cayenne.access.DataContextQueryAction.execute(DataContextQueryAct
ion.java:54)
	at
org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1387)
	at
org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1376)
	at
com.thalesgroup.trt.uk.p7513.gsmgateway.portals.DPSPortal_BindingImpl.getEve
nts(DPSPortal_BindingImpl.java:126)
	at
com.thalesgroup.trt.uk.p7513.gsmgateway.interfaces.dpsportal.DPSPortal_Bindi
ngSkeleton.getEvents(DPSPortal_BindingSkeleton.java:134)
	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.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397
)
	at
org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:1
86)
	at
org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
	at
org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:
32)
	at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
	at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
	at
org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)
	at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
	at
org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at
org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:
327)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:269)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:188)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:210)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:174)
	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127
)
	at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117
)
	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:108)
	at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
	at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
	at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processC
onnection(Http11BaseProtocol.java:665)
	at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.jav
a:528)
	at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWo
rkerThread.java:81)
	at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:685)
	at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.cayenne.exp.ExpressionException: [v.2.0.3 May 6 2007]
Can't resolve path component: [EventsDB.EVENT_ID].
	at org.apache.cayenne.map.Entity$PathIterator.next(Entity.java:363)
	at
org.apache.cayenne.access.trans.QueryAssemblerHelper.appendObjPath(QueryAsse
mblerHelper.java:89)
	at
org.apache.cayenne.access.trans.QualifierTranslator.objectNode(QualifierTran
slator.java:339)
	at org.apache.cayenne.exp.Expression.traverse(Expression.java:514)
	at org.apache.cayenne.exp.Expression.traverse(Expression.java:511)
	at org.apache.cayenne.exp.Expression.traverse(Expression.java:491)
	at
org.apache.cayenne.access.trans.QualifierTranslator.doTranslation(QualifierT
ranslator.java:74)
	at
org.apache.cayenne.access.trans.SelectTranslator.createSqlString(SelectTrans
lator.java:129)
	at
org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssemble
r.java:95)
	at
org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:
71)
	at
org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.j
ava:59)
	at
org.apache.cayenne.access.DataNode.performQueries(DataNode.java:273)
	... 43 more

*******************************************************************************
Please consider the environment before printing this email.
*******************************************************************************
This email and any files transmitted with it are intended solely for the use of
the individual or entity to whom they are addressed and may not be divulged to
any third party without the express permission of the originator.  Any views
expressed in this message are those of the individual sender, except where the
sender specifically states them to be the views of Thales Research & Technology
(UK) Limited.
*******************************************************************************


Re: Querying a Primary Key

Posted by Mike Kienenberger <mk...@gmail.com>.
One thing you can probably do is use a database or dbentity path
expression instead of a objentity path expression.   This would allow
you to refer to the database column directly rather than using the
ObjAttribute name.

I can't remember the syntax for that, but it seems like it was
something like "db:COLUMN_NAME" instead of "attributeName"


On 8/15/07, Griffiths Guy <Gu...@thalesgroup.com> wrote:
> Hi,
> I am writing an application which requires me to query an auto-generated
> Primary Key, but I am currently getting a "Can't resolve path component"
> error.
>
> Basically, my application has a table of generated Events, with a
> database-generated PK in the column EVENT_ID.  Using the Cayenne Modeler I
> have not made this visible, but I have added this method:
>
>     public Long getEventID() {
>        return (getObjectId() != null &&
>                    !getObjectId().isTemporary())
>                             ?
>
> (Long)getObjectId().getIdSnapshot().get(EVENT_ID_PK_COLUMN)
>                             : null;
>     }
>
> to the EventsDB class (i.e. the non-auto-generated one).  I based this on
> the method here:
> http://cayenne.apache.org/doc20/accessing-pk-and-fk-values.html
>
> I need the end user to be able to obtain all rows from the Events table
> since a specified event.  They will know the EventID of the last event they
> obtained from the above method.
>
> To do this, I am using a select query with the following qualifier:
>
> ExpressionFactory.greaterExp(EventsDB.EVENT_ID_PK_COLUMN, since);
>
> Where "since" is a Long which is set to the value of the previous known
> EventID.
>
> However, when I try and perform this query, I get the error:
> Can't resolve path component: [EventsDB.EVENT_ID]
>
> The auto-generated _EventsDB.java has defined EventsDB.EVENT_ID_PK_COLUMN as
> public static final String EVENT_ID_PK_COLUMN = "EVENT_ID";
>
> The PK column name is of course EVENT_ID.
>
> I would be very grateful if anyone could suggest what is going wrong and how
> to remedy it, or a possible workaround.  I have tried making the EVENT_ID
> column correspond to an object in the Cayenne Modeler (despite the warning
> it throws up), and using EventsDB.EVENT_ID_PROPERTY in the query, but this
> gives near identical errors.  I have also tried rebuilding the database etc.
>
> I am using Cayenne v2.0.3 and I have included the full stack trace as a
> footer to this message.
>
> Thanks in advance for any help anyone can provide.
>
> Guy Griffiths
>
> --
> org.apache.cayenne.CayenneRuntimeException: [v.2.0.3 May 6 2007] Query
> exception.
>         at
> org.apache.cayenne.access.DataDomainQueryAction.nextQueryException(DataDomai
> nQueryAction.java:428)
>         at
> org.apache.cayenne.access.DataNode.performQueries(DataNode.java:280)
>         at
> org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryActi
> on.java:301)
>         at
> org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAc
> tion.java:60)
>         at
> org.apache.cayenne.access.DataDomainQueryAction$1.transform(DataDomainQueryA
> ction.java:273)
>         at
> org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:836)
>         at
> org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDo
> mainQueryAction.java:270)
>         at
> org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryActio
> n.java:110)
>         at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:746)
>         at
> org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQuery
> Action.java:217)
>         at
> org.apache.cayenne.access.DataContextQueryAction.execute(DataContextQueryAct
> ion.java:54)
>         at
> org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1387)
>         at
> org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1376)
>         at
> com.thalesgroup.trt.uk.p7513.gsmgateway.portals.DPSPortal_BindingImpl.getEve
> nts(DPSPortal_BindingImpl.java:126)
>         at
> com.thalesgroup.trt.uk.p7513.gsmgateway.interfaces.dpsportal.DPSPortal_Bindi
> ngSkeleton.getEvents(DPSPortal_BindingSkeleton.java:134)
>         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.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397
> )
>         at
> org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:1
> 86)
>         at
> org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
>         at
> org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:
> 32)
>         at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
>         at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
>         at
> org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)
>         at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
>         at
> org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
>         at
> org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:
> 327)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
> FilterChain.java:269)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
> ain.java:188)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
> va:210)
>         at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
> va:174)
>         at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127
> )
>         at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117
> )
>         at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
> :108)
>         at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
>         at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
>         at
> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processC
> onnection(Http11BaseProtocol.java:665)
>         at
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.jav
> a:528)
>         at
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWo
> rkerThread.java:81)
>         at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
> a:685)
>         at java.lang.Thread.run(Thread.java:619)
> Caused by: org.apache.cayenne.exp.ExpressionException: [v.2.0.3 May 6 2007]
> Can't resolve path component: [EventsDB.EVENT_ID].
>         at org.apache.cayenne.map.Entity$PathIterator.next(Entity.java:363)
>         at
> org.apache.cayenne.access.trans.QueryAssemblerHelper.appendObjPath(QueryAsse
> mblerHelper.java:89)
>         at
> org.apache.cayenne.access.trans.QualifierTranslator.objectNode(QualifierTran
> slator.java:339)
>         at org.apache.cayenne.exp.Expression.traverse(Expression.java:514)
>         at org.apache.cayenne.exp.Expression.traverse(Expression.java:511)
>         at org.apache.cayenne.exp.Expression.traverse(Expression.java:491)
>         at
> org.apache.cayenne.access.trans.QualifierTranslator.doTranslation(QualifierT
> ranslator.java:74)
>         at
> org.apache.cayenne.access.trans.SelectTranslator.createSqlString(SelectTrans
> lator.java:129)
>         at
> org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssemble
> r.java:95)
>         at
> org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:
> 71)
>         at
> org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.j
> ava:59)
>         at
> org.apache.cayenne.access.DataNode.performQueries(DataNode.java:273)
>         ... 43 more
>
> *******************************************************************************
> Please consider the environment before printing this email.
> *******************************************************************************
> This email and any files transmitted with it are intended solely for the use of
> the individual or entity to whom they are addressed and may not be divulged to
> any third party without the express permission of the originator.  Any views
> expressed in this message are those of the individual sender, except where the
> sender specifically states them to be the views of Thales Research & Technology
> (UK) Limited.
> *******************************************************************************
>
>