cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Garcia Corral, Josep" <josep.gar...@tecsidel.es>
Subject RE: how can I use two different databases in one web application?
Date Fri, 09 May 2008 14:45:43 GMT
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:blacknext@gmail.com] 
Enviado el: viernes, 09 de mayo de 2008 16:41
Para: user@cayenne.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.garcia@tecsidel.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.SelectQuery@ceb042[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:blacknext@gmail.com]
> Enviado el: viernes, 09 de mayo de 2008 16:08
> Para: user@cayenne.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.garcia@tecsidel.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
>>
>>
>>
>>
>

Mime
View raw message