RE: how can I use two different databases in one web application?

From: Garcia Corral, Josep (josep.garci..ecsidel.es)
Date: Tue May 13 2008 - 08:54:24 EDT

  • Next message: Mike Kienenberger: "Re: one-to-many problem"

    Correct!
    I had duplicate cayenne files and some where missing in the correct
    folder.

    Thanks for your help!

    -----Mensaje original-----
    De: Michael Gentry [mailto:blacknex..mail.com]
    Enviado el: viernes, 09 de mayo de 2008 18:19
    Para: use..ayenne.apache.org
    Asunto: Re: how can I use two different databases in one web
    application?

    I just did a quick test with one DataDomain, 2 DataNodes, 2 DataMaps.
    One DataNode connecting to Derby and the other connecting to MySQL. I
    was able to insert/select from both databases without an issue.
    Admittedly, I'm using Cayenne 3, but I don't think that should be a
    problem. It really sounds like you have a mapping issue in the model,
    especially given the error message "No DataMap found, can't route
    query". I'd double-check everything in the model for starters.

    On Fri, May 9, 2008 at 10:45 AM, Garcia Corral, Josep
    <josep.garci..ecsidel.es> wrote:
    > Both of them are correctly assigned.
    >
    > Here's the cayenne.xml contents:
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <domains project-version="2.0">
    > <domain name="LibroDecretosDomain">
    >
    > <map name="IdmDomainMap" location="IdmDomainMap.map.xml"/>
    > <map name="LibroDecretosDomainMap"
    > location="LibroDecretosDomainMap.map.xml"/>
    >
    > <node name="IdmDomainNode"
    > datasource="IdmDomainNode.driver.xml"
    >
    > factory="org.apache.cayenne.conf.DriverDataSourceFactory">
    > <map-ref name="IdmDomainMap"/>
    > </node>
    > <node name="LibroDecretosDomainNode"
    > datasource="LibroDecretosDomainNode.driver.xml"
    >
    > factory="org.apache.cayenne.conf.DriverDataSourceFactory">
    > <map-ref name="LibroDecretosDomainMap"/>
    > </node>
    > </domain>
    > </domains>
    >
    > -----Mensaje original-----
    > De: Michael Gentry [mailto:blacknex..mail.com]
    > Enviado el: viernes, 09 de mayo de 2008 16:41
    > Para: use..ayenne.apache.org
    > Asunto: Re: how can I use two different databases in one web
    > application?
    >
    > Make sure your DataMaps are assigned to DataNodes. In Cayenne
    > Modeler, select each DataMap and look at the DataNode pulldown list
    > (under the DataMap Configuration sectoin) and make sure it is assigned
    > to the right DataNode.
    >
    > On Fri, May 9, 2008 at 10:31 AM, Garcia Corral, Josep
    > <josep.garci..ecsidel.es> wrote:
    >> Thanks for your reply.
    >> I tried your suggestion:
    >>
    >> HttpSession session = req.getSession();
    >> DataContext context = ServletUtil.getSessionContext(session);
    >> Expression qualifier =
    >> Expression.fromString(some_condition_for_table_A);
    >> SelectQuery select = new SelectQuery(A.class, qualifier);
    >> List<A> mylistA = context.performQuery(select);
    >> ...
    >>
    >> qualifier = Expression.fromString(some_condition_for_table_C);
    >> select = new SelectQuery(C.class, qualifier);
    >> List<C> grType = context.performQuery(select);
    >> ...
    >>
    >> I get an exception in the second SelectQuery:
    >>
    >> No DataMap found, can't route query
    >> org.apache.cayenne.query.SelectQuer..eb042[root=class
    >> com.tecsidel.db.IdmGroupType,name=<null>]
    >>
    >> A and C are invented names to simplify the code.
    >>
    >> Any help will be appreciated.
    >>
    >>
    >> -----Mensaje original-----
    >> De: Michael Gentry [mailto:blacknex..mail.com]
    >> Enviado el: viernes, 09 de mayo de 2008 16:08
    >> Para: use..ayenne.apache.org
    >> Asunto: Re: how can I use two different databases in one web
    >> application?
    >>
    >> I suspect you are wanting to access both databases at the same time
    >> and within the same DataContext? If so, try your second option (one
    >> DataDomain, two DataMaps, two DataNodes -- one DataMap assigned to
    >> your Oracle DataNode and the other DataMap assigned to your MySQL
    >> DataNode). Then create a DataContext normally (no parameters).
    >> Cayenne should be able to route to the proper database (through the
    >> DataNode) depending on which classes you are using (defined in the
    >> DataMaps). Just make sure you have totally separate classes (don't
    >> try to reuse the same class in two DataMaps).
    >>
    >> Let us know if you have other issues.
    >>
    >> /dev/mrg
    >>
    >>
    >> On Fri, May 9, 2008 at 8:17 AM, Garcia Corral, Josep
    >> <josep.garci..ecsidel.es> wrote:
    >>> Hello,
    >>>
    >>> I am using the last stable version of Cayenne: 2.0.4.
    >>>
    >>>
    >>>
    >>> The situation is:
    >>>
    >>> Database 1: oracle, with tables A, B
    >>>
    >>> Database 2: mysql, with tables C, D, E
    >>>
    >>>
    >>>
    >>> First question is: what's the best way to define this in a Cayenne
    >>> Project?
    >>>
    >>>
    >>>
    >>> First_Domain:
    >>>
    >>> First_DomainMap
    >>>
    >>> First_DomainNode
    >>>
    >>> Second_Domain:
    >>>
    >>> Second_DomainMap
    >>>
    >>> Second_DomainNode
    >>>
    >>>
    >>>
    >>> or:
    >>>
    >>>
    >>>
    >>> Domain:
    >>>
    >>> First_DomainMap
    >>>
    >>> First_DomainNode
    >>>
    >>> Second_DomainMap
    >>>
    >>> Second_DomainNode
    >>>
    >>>
    >>>
    >>> And then, from a servlet, how can I have access to tables from
    >> Database
    >>> 1 and 2? What I have used so far is:
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> I tried this but it did not work:
    >>>
    >>> DataContext.createDataContext("First_Domain");
    >>>
    >>> ...
    >>>
    >>>
    >>>
    >>> This did not work either:
    >>>
    >>> HttpSession session = req.getSession();
    >>>
    >>> DataContext context = ServletUtil.getSessionContext(session);
    >>>
    >>> Expression qualifier = Expression.fromString(some_condition);
    >>>
    >>> SelectQuery select = new SelectQuery(A.class, qualifier);
    >>>
    >>> ...
    >>>
    >>> qualifier = Expression.fromString(other_condition);
    >>>
    >>> select = new SelectQuery(C.class, qualifier);
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> Josep Garcia
    >>>
    >>>
    >>>
    >>>
    >>
    >



    This archive was generated by hypermail 2.0.0 : Tue May 13 2008 - 08:54:58 EDT