executing raw sql

From: Martin Ruff (mruf..imeon.ch)
Date: Thu May 08 2003 - 08:43:08 EDT

  • Next message: Andrus Adamchik: "Re: executing raw sql"

    Hi,
    I'd like to execute the following sql
    delete from tmp_cm_user_kpi
    INSERT INTO tmp_cm_user_kpi (tmp_cm_user_kpi_id, kpi_id, kpi_value,
    valuta_timestamp, user_id) SELECT user_kpi_id, kpi_id, kpi_value,
    max(valuta_timestamp), user_id FROM cm_user_kpi where kpi_id = 1 group by
    user_id;
    select distinct a.* from cm_user_kpi a, tmp_cm_user_kpi b WHERE a.kpi_id =
    b.kpi_id and a.valuta_timestamp = b.valuta_timestamp order by kpi_value
    desc;

    I tried:
                    SqlSelectQuery kpiscoresquery = new SqlSelectQuery();
                    kpiscoresquery.setSqlString("select distinct a.* from cm_user_kpi a,
    tmp_cm_user_kpi b WHERE a.kpi_id = b.kpi_id and a.valuta_timestamp =
    b.valuta_timestamp order by kpi_value desc");
                    ctxt.performQuery(kpiscoresquery, new ScoreQueryObserver(this));
    I get the error:
    org.objectstyle.cayenne.CayenneRuntimeException: Could not find DbEntity
    for query with root :null
    but which one should be the root?
    cm_user_kpi or tmp_cm_user_kpi
    my observer looks like this:
    public class ScoreQueryObserver implements OperationObserver
    {
            private LocalCompetitionManager Caller;
            public ScoreQueryObserver(LocalCompetitionManager caller)
            {
                    this.Caller = caller;
            }
            public void nextBatchCount(Query query, int[] resultCount)
            {
            }
            public void nextCount(Query query, int resultCount)
            {
            }
            public void nextDataRows(Query query, java.util.List dataRows)
            {
            }
            public void nextDataRows(Query q, ResultIterator it)
            {
            }
            public void nextGlobalException(java.lang.Exception ex)
            {
            }
            public void nextQueryException(Query query, java.lang.Exception ex)
            {
            }
            public java.util.List orderQueries(DataNode aNode, java.util.List queryList)
            {
                    return null;
            }
            public void transactionCommitted()
            {
            }
            public void transactionRolledback()
            {
            }

            public Level getLoggingLevel()
            {
                    return Level.WARN;
            }
            public boolean isIteratedResult()
            {
                    return false;
            }
            public boolean useAutoCommit()
            {
                    return true;
            }

    }
    thanks for help
    martin
    -------------------------------------------
    Be the change you want to see in the world.



    This archive was generated by hypermail 2.0.0 : Thu May 08 2003 - 08:42:55 EDT