Re: Loading data maps from JARs

From: Borut Bolčina (borut.bolcin..mail.com)
Date: Tue Feb 16 2010 - 10:42:00 EST

  • Next message: Nishant Neeraj: "Registering Objects"

    I had a dependency problem in my POM. The dependeny type was set to pom
    instead of jar. The configuration seems to go ok now (both maps get loaded),
    but I still can not do queries.

            DefaultConfiguration conf = new
    DefaultConfiguration("redbox-cayenne.xml");
            Configuration.initializeSharedConfiguration(conf);

            DataContext context = DataContext.createDataContext();

            SelectQuery q = new SelectQuery(Logo.class);
            List<Logo> logos = context.performQuery(q);

            for (Logo logo : logos) {
                logger.info(logo);
            }

            DataContext context2 = DataContext.createDataContext();
            q = new SelectQuery(Fund.class);
            List<Fund> funds = context2.performQuery(q);

            for (Fund fund : funds) {
                logger.info(fund);
            }

    gives me:

    DEBUG [16:00:40.013] [org.apache.cayenne.conf.DefaultConfiguration] using
    domain file name: redbox-cayenne.xml
    DEBUG [16:00:40.016] [org.apache.cayenne.conf.DefaultConfiguration]
    initialize starting.
     INFO [16:00:40.026] [org.apache.cayenne.conf.RuntimeLoadDelegate] started
    configuration loading.
     INFO [16:00:40.028] [org.apache.cayenne.conf.RuntimeLoadDelegate] loaded
    domain: MyDomain
     INFO [16:00:40.095] [org.apache.cayenne.conf.RuntimeLoadDelegate] loaded
    <map name='LogotypesMap' location='LogotypesMap.map.xml'>.
     INFO [16:00:40.128] [org.apache.cayenne.conf.RuntimeLoadDelegate] loaded
    <map name='StartpageMap' location='StartpageMap.map.xml'>.
     INFO [16:00:40.129] [org.apache.cayenne.conf.RuntimeLoadDelegate] loading
    <node name='LogotypesNode' datasource='dbcp-logotypes.properties'
    factory='org.apache.cayenne.conf.DBCPDataSourceFactory'
    schema-update-strategy='org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy'>.
     INFO [16:00:40.135] [org.apache.cayenne.conf.RuntimeLoadDelegate] using
    factory: org.apache.cayenne.conf.DBCPDataSourceFactory
    DEBUG [16:00:40.137] [org.apache.cayenne.conf.DBCPDataSourceFactory] DBCP
    Properties: {cayenne.dbcp.validationQuery="SELECT 1 FROM AUTO_PK_SUPPORT;",
    cayenne.dbcp.url=jdbc:mysql://
    acme.interseek.com:3306/logotypes?characterEncoding=utf8&amp;autoReconnect=true,
    cayenne.dbcp.maxActive=50, cayenne.dbcp.maxIdle=8,
    cayenne.dbcp.password=mypassword, cayenne.dbcp.maxWait=10000,
    cayenne.dbcp.minIdle=5, cayenne.dbcp.driverClassName=com.mysql.jdbc.Driver,
    cayenne.dbcp.username=backend}
     INFO [16:00:40.155] [org.apache.cayenne.conf.RuntimeLoadDelegate] loaded
    datasource.
     INFO [16:00:40.155] [org.apache.cayenne.conf.RuntimeLoadDelegate] no
    adapter set, using automatic adapter.
     INFO [16:00:40.164] [org.apache.cayenne.conf.RuntimeLoadDelegate] loaded
    map-ref: LogotypesMap.
     INFO [16:00:40.164] [org.apache.cayenne.conf.RuntimeLoadDelegate] loading
    <node name='StartpageNode' datasource='dbcp.properties'
    factory='org.apache.cayenne.conf.DBCPDataSourceFactory'
    schema-update-strategy='org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy'>.
     INFO [16:00:40.164] [org.apache.cayenne.conf.RuntimeLoadDelegate] using
    factory: org.apache.cayenne.conf.DBCPDataSourceFactory
    DEBUG [16:00:40.165] [org.apache.cayenne.conf.DBCPDataSourceFactory] DBCP
    Properties: {cayenne.dbcp.validationQuery="SELECT 1 FROM AUTO_PK_SUPPORT;",
    cayenne.dbcp.url=jdbc:mysql://
    acme.interseek.com:3306/portal_prod?characterEncoding=utf8&amp;autoReconnect=true,
    cayenne.dbcp.maxActive=50, cayenne.dbcp.maxIdle=8,
    cayenne.dbcp.password=mypassword, cayenne.dbcp.maxWait=10000,
    cayenne.dbcp.minIdle=5, cayenne.dbcp.driverClassName=com.mysql.jdbc.Driver,
    cayenne.dbcp.username=backend}
     INFO [16:00:40.165] [org.apache.cayenne.conf.RuntimeLoadDelegate] loaded
    datasource.
     INFO [16:00:40.165] [org.apache.cayenne.conf.RuntimeLoadDelegate] no
    adapter set, using automatic adapter.
     INFO [16:00:40.166] [org.apache.cayenne.conf.RuntimeLoadDelegate] loaded
    map-ref: StartpageMap.
     INFO [16:00:40.170] [org.apache.cayenne.map.EntityResolver] added runtime
    complimentary ObjRelationship from Bookmark to UserBookmark
    DEBUG [16:00:40.171] [org.apache.cayenne.conf.Configuration] added domain:
    MyDomain
     INFO [16:00:40.171] [org.apache.cayenne.conf.RuntimeLoadDelegate] finished
    configuration loading in 145 ms.
    DEBUG [16:00:40.171] [org.apache.cayenne.conf.DefaultConfiguration]
    initialize finished.
    ERROR [16:00:40.213] [org.quartz.core.JobRunShell] Job reader.gold-logotypes
    threw an unhandled Exception:
    org.apache.cayenne.CayenneRuntimeException: [v.3.0RC1 Jan 05 2010 14:44:59]
    No DataMap found, can't route query
    org.apache.cayenne.query.SelectQuer..71f735[root=class
    si.planet9.logotypes.model.Logo,name=<null>]
        at org.apache.cayenne.query.AbstractQuery.route(AbstractQuery.java:134)
        at org.apache.cayenne.query.SelectQuery.route(SelectQuery.java:164)
        at
    org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:410)
        at
    org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:65)
        at
    org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:391)
        at
    org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:850)
        at
    org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:388)
        at
    org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:117)
        at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:743)
        at
    org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:333)
        at
    org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
        at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1278)
        at
    org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1267)
        at
    si.najdi.redbox.goldlogotypes.GoldLogotypesReaderJob.execute(GoldLogotypesReaderJob.java:39)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        at
    org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
    ERROR [16:00:40.218] [org.quartz.core.ErrorLogger] Job
    (reader.gold-logotypes threw an exception.
    org.quartz.SchedulerException: Job threw an unhandled exception. [See nested
    exception: org.apache.cayenne.CayenneRuntimeException: [v.3.0RC1 Jan 05 2010
    14:44:59] No DataMap found, can't route query
    org.apache.cayenne.query.SelectQuer..71f735[root=class
    si.planet9.logotypes.model.Logo,name=<null>]]
        at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
        at
    org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
    Caused by: org.apache.cayenne.CayenneRuntimeException: [v.3.0RC1 Jan 05 2010
    14:44:59] No DataMap found, can't route query
    org.apache.cayenne.query.SelectQuer..71f735[root=class
    si.planet9.logotypes.model.Logo,name=<null>]
        at org.apache.cayenne.query.AbstractQuery.route(AbstractQuery.java:134)
        at org.apache.cayenne.query.SelectQuery.route(SelectQuery.java:164)
        at
    org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:410)
        at
    org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:65)
        at
    org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:391)
        at
    org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:850)
        at
    org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:388)
        at
    org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:117)
        at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:743)
        at
    org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:333)
        at
    org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
        at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1278)
        at
    org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1267)
        at
    si.najdi.redbox.goldlogotypes.GoldLogotypesReaderJob.execute(GoldLogotypesReaderJob.java:39)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        ... 1 more

    There are three (3) cayenne configuration files on the classpath
     - two cayenne.xml (one in each model jar) and
     - redbox-cayenne.xml (in my web app)

    Is it possible that cayenne picks up either of cayenne.xml files despite I
    am explicitly loading redbox-cayenne.xml with

    DefaultConfiguration conf = new DefaultConfiguration("redbox-cayenne.xml");

    -Borut

    2010/2/16 Andrus Adamchik <andru..bjectstyle.org>

    >
    > On Feb 16, 2010, at 2:38 PM, Borut Bolčina wrote:
    >
    > Question is: Can ResourceLocator be configured to read mapping files
    >> my-map-1.map.xml and my-map-2.map.xml from the root of project-model1.jar
    >> and project-model2.jar?
    >>
    >> The DefaultConfiguration read from classpath, but it seems it does not
    >> find
    >> mapping files inside the JARs (at root of it).
    >>
    >
    > It is odd that it doesn't work. When looking for DataMap XML file all
    > Cayenne does is ClassLoader.getResource()
    >
    > Andrus
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Feb 16 2010 - 10:42:38 EST