FAQ
Hi,

I am still pursuing the idea of loading cayenne configuration files from
different locations. I need an advice on how to load mapping files from
different location other then the same location as cayenne.xml.

I am looking at the source code (Configuration, DefaultConfiguration,
RuntimeLoadDElegate, ResourceLocator,...) and did't just figured it out.

I have project-model1 with:
cayenne.xml
my-map-1.map.xml
and some data object classes

and project-model2 with
cayenne.xml
my-map-2.map.xml
and some data object classes.

Now in my web project I need data objects from both JARs (project-model1.jar
and project-model2.jar). The web project has "manually crafted" cayenne.xml
which is read by

DefaultConfiguration conf = new
DefaultConfiguration("my-manually-crafted-cayenne.xml");
Configuration.initializeSharedConfiguration(conf);

my-manually-crafted-cayenne.xml looks like:

<?xml version="1.0" encoding="utf-8"?>
<domains project-version="3.0.0.1">
<domain name="MyDomain">
<map name="my-map-1" location="my-map-1.map.xml"/>
<map name="my-map-2" location="my-map-2.map.xml"/>

<node name="my-map-1Node"
datasource="dbcp-1.properties"
factory="org.apache.cayenne.conf.DBCPDataSourceFactory">
<map-ref name="my-map-1"/>
</node>

<node name="my-map-2Node"
datasource="dbcp-2.properties"
factory="org.apache.cayenne.conf.DBCPDataSourceFactory">
<map-ref name="my-map-2"/>
</node>
</domain>
</domains>


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).

Thanks for tips,
Borut

Search Discussions

  • Andrus Adamchik at Feb 16, 2010 at 1:00 pm

    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
  • Borut Bolčina at Feb 16, 2010 at 3:42 pm
    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.SelectQuery@171f735[root=class
    si.planet9.logotypes.model.Logo,name=(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 201
    14:44:59] No DataMap found, can't route query
    org.apache.cayenne.query.SelectQuery@171f735[root=class
    si.planet9.logotypes.model.Logo,name=(JobRunShell.java:213)
    at
    org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
    Caused by: org.apache.cayenne.CayenneRuntimeException: [v.3.0RC1 Jan 05 201
    14:44:59] No DataMap found, can't route query
    org.apache.cayenne.query.SelectQuery@171f735[root=class
    si.planet9.logotypes.model.Logo,name=(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 <andrus@objectstyle.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
  • Andrus Adamchik at Feb 17, 2010 at 9:12 am

    On Feb 16, 2010, at 5:42 PM, Borut Bolčina wrote:

    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");

    No, redbox-cayenne.xml is read correctly from the logs (and from
    checking the code). Looks like that DataMap is not mapped to a
    DataNode though.

    Andrus
  • Borut Bolčina at Feb 17, 2010 at 10:14 am
    OK, after setting some more DEBUG logging
    (log4j.logger.org.apache.cayenne.util=DEBUG) I found out that one of the
    model jars actually included a false copy of mapping file - the one that
    should be in the other model jar. Somehow new SNAPSHOT jar was not picked up
    by my web app. God damn. I assumed how the model jar looks like and caught
    myself in the saying: "Assumption is the mother of all fuckups!"

    Now everything works, but I believe I got the ulcer...need a holiday.

    Thanks for help.

    2010/2/17 Andrus Adamchik <andrus@objectstyle.org>
    On Feb 16, 2010, at 5:42 PM, Borut Bolčina wrote:

    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");

    No, redbox-cayenne.xml is read correctly from the logs (and from checking
    the code). Looks like that DataMap is not mapped to a DataNode though.

    Andrus

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedFeb 16, '10 at 12:39p
activeFeb 17, '10 at 10:14a
posts5
users2
websitecayenne.apache.org

2 users in discussion

Borut Bolčina: 3 posts Andrus Adamchik: 2 posts

People

Translate

site design / logo © 2022 Grokbase