cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: Multiple Databases and Setting Connection
Date Wed, 07 Jun 2006 06:03:06 GMT
The situation you describe is addressed by multiple DataDomains (data  
domain is the first thing you create in the Modeler when starting a  
project). One catch is that you can't share the DataMap between  
domains using the Modeler. So you may have to do some runtime  
configuration. E.g. you can have the following structure setup in the  


Then you can do this on startup to share the DataMap (I think Michael  
also posted a similar example some time back)

// find the DataMap
Configuration c = Configuration.getSharedConfiguration();
DataDomain d1 = c.getDomain("DD1");
DataMap m1 = d1.getMap("DM1");

// link it to a second domain
DataDomain d2 = c.getDomain("DD2");
DataNode n2 = d2.getNode("DN2");

Another catch with multiple DataDomains is that you have to pass an  
appropriate domain name when creating a DataContext for a given user.  
So instead of

DataContext dc = DataContext.createDataContext();

you'd have to do something like this:

String domainName = ... // determine based on user group
DataContext dc = DataContext.createDataContext(domainName);


On Jun 7, 2006, at 4:22 AM, james wrote:

> Gentry, Michael (Contractor <michael_gentry <at>>  
> writes:
>> You need to have multiple DataNodes in your model -- one for each
>> database.  You also need multiple DataMaps.  Each DataMap should  
>> contain
>> the schema for one of the databases.  Then in the modeler, under the
>> DataMap Configuration section, select the DataNode to associate  
>> the map
>> to.  Cayenne will then use the right database connection for the  
>> objects
>> you are working upon.
> Hi,
>    I have different groups of web users. A new database is created  
> for each
> group. Hence I need one DataMap and multiple DataNodes. Can one  
> DataMap be
> assigned to two or more DataNodes?
> Regards,
> James

View raw message