Re: newbie question

From: Borut Bolčina (borut.bolcin..mail.com)
Date: Tue Apr 22 2008 - 09:33:40 EDT

  • Next message: Andrus Adamchik: "Re: newbie question"

    Thanks,

    I am getting error with this:

            String ejbql = "SELECT max(id) FROM Event";
            Integer maxId = (Integer) DataObjectUtils.objectForQuery(context,
    new EJBQLQuery(ejbql));

    it says:

            org.apache.cayenne.CayenneRuntimeException: [v.3.0M3 Feb 03 2008
    21:10:17] Query exception.
    org.apache.cayenne.CayenneRuntimeException: [v.3.0M3 Feb 03 2008 21:10:17]
    Query exception.
            at
    org.apache.cayenne.access.DataDomainQueryAction.nextQueryException(DataDomainQueryAction.java:638)
            at
    org.apache.cayenne.access.DataNode.performQueries(DataNode.java:237)
            at
    org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:442)
            at
    org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:67)
            at
    org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:415)
            at
    org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:847)
            at
    org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:412)
            at
    org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:119)
            at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:740)
            at
    org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:296)
            at
    org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:84)
            at
    org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1331)
            at
    org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1320)
            at
    org.apache.cayenne.DataObjectUtils.objectForQuery(DataObjectUtils.java:275)
            at
    com.interseek.events.EventsIndexServer.createIndexFromEvents(EventsIndexServer.java:228)
            at
    com.interseek.events.EventsIndexServer.<init>(EventsIndexServer.java:118)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
    Method)
            at
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
            at
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
            at
    si.noviforum.TxtIndex5.IndexDirectory.IndexDirectory$1RemoteThread.run(IndexDirectory.java:370)
    Caused by: org.apache.cayenne.ejbql.EJBQLException: [v.3.0M3 Feb 03 2008
    21:10:17] Invalid identification variable: id
            at
    org.apache.cayenne.access.jdbc.EJBQLPathTranslator.visitIdentifier(EJBQLPathTranslator.java:85)
            at
    org.apache.cayenne.ejbql.parser.EJBQLIdentifier.visit(EJBQLIdentifier.java:35)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:84)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
            at
    org.apache.cayenne.access.jdbc.EJBQLAggregateColumnTranslator.visitAggregateColumn(EJBQLAggregateColumnTranslator.java:86)
            at
    org.apache.cayenne.access.jdbc.EJBQLAggregateColumnTranslator.visitMax(EJBQLAggregateColumnTranslator.java:56)
            at
    org.apache.cayenne.ejbql.parser.EJBQLMax.visitNode(EJBQLMax.java:35)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:60)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:84)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
            at
    org.apache.cayenne.access.jdbc.EJBQLSelectColumnsTranslator.visitAggregate(EJBQLSelectColumnsTranslator.java:54)
            at
    org.apache.cayenne.ejbql.parser.EJBQLAggregate.visitNode(EJBQLAggregate.java:35)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:60)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:84)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:84)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
            at
    org.apache.cayenne.access.jdbc.EJBQLSelectTranslator.visitSelectExpressions(EJBQLSelectTranslator.java:112)
            at
    org.apache.cayenne.ejbql.parser.EJBQLSelectExpressions.visitNode(EJBQLSelectExpressions.java:35)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:60)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:84)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visitChild(SimpleNode.java:84)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:64)
            at
    org.apache.cayenne.access.jdbc.EJBQLAction$1.visitSelect(EJBQLAction.java:73)
            at
    org.apache.cayenne.ejbql.parser.EJBQLSelect.visitNode(EJBQLSelect.java:35)
            at
    org.apache.cayenne.ejbql.parser.SimpleNode.visit(SimpleNode.java:60)
            at
    org.apache.cayenne.access.jdbc.EJBQLAction.performAction(EJBQLAction.java:67)
            at
    org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)
            at
    org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
            ... 19 more

    It seems attribute id is not allowed as object entity and db entity? Here is
    a partial mapping:

        <db-entity name="event">
            <db-attribute name="category" type="VARCHAR" isMandatory="true"
    length="255"/>
            <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    isMandatory="true" length="11"/>
            <db-attribute name="location" type="VARCHAR" length="255"/>
            <db-attribute name="title" type="VARCHAR" isMandatory="true"
    length="255"/>
        </db-entity>
        <obj-entity name="Event" className="com.mycompany.events.model.Event"
    dbEntityName="event">
            <obj-attribute name="category" type="java.lang.String"
    db-attribute-path="category"/>
            <obj-attribute name="id" type="java.lang.Integer"
    db-attribute-path="id"/>
            <obj-attribute name="location" type="java.lang.String"
    db-attribute-path="location"/>
            <obj-attribute name="title" type="java.lang.String"
    db-attribute-path="title"/>
        </obj-entity>

    Why the restriction?

    Cheers,
    Borut
    2008/4/22 Andrus Adamchik <andrus@objectstyle.org>:

    > String ejbql = "SELECT max(p.estimatedPrice) FROM Painting p";
    > Number n = (Number) DataObjectUtils.objectForQuery(context, new
    > EJBQLQuery(ejbql));
    >
    >
    > Andrus
    >
    >
    > On Apr 22, 2008, at 2:47 PM, Borut Bolčina wrote:
    >
    > Hello Andrus,
    > >
    > > what is the elegant 3.0M3 Cayenne way to do select MAX?
    > >
    > > Thanks,
    > > Borut
    > >
    > > 2007/10/9 Andrus Adamchik <andrus@objectstyle.org>:
    > >
    > > Hi Jan,
    > > >
    > > > Looks like what you need is a SQLTemplate query:
    > > >
    > > > http://cayenne.apache.org/doc/sqltemplate-query.html
    > > >
    > > > Here is a mockup code example:
    > > >
    > > > SQLTemplate q = new SQLTemplate(SomeClass.class, "select MAX(id) from
    > > > table");
    > > > q.setFetchingDataRows(true);
    > > >
    > > > Map row = (Map) DataObjectUtils.objectForQuery(q);
    > > > Number id = (Number) row.values().iterator().next();
    > > >
    > > > (Cayenne 3.0 will be featuring more elegant API to achieve that, but
    > > > still
    > > > the code above should work just as well)
    > > >
    > > > Andrus
    > > >
    > > >
    >



    This archive was generated by hypermail 2.0.0 : Tue Apr 22 2008 - 09:34:38 EDT