cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <>
Subject Re: Unit Testing cayenne apps
Date Tue, 23 Apr 2013 14:42:35 GMT
You can configure the database connection in 3.1 with a module like:

import org.apache.cayenne.configuration.Constants;
import org.apache.cayenne.di.Binder;
import org.apache.cayenne.di.Module;

public class AppModule implements Module {
 public void configure(Binder binder) {


You just have to list your module when creating the ServerRuntime:

CayenneRuntime runtime = new ServerRuntime("cayenne-MyDomain.xml", new

It can also be specified in web.xml instead if you are using CayenneFilter
or something.

The JDBC_URL_PROPERTY will override the url for all databases.  If you have
more than one you'll want to override each independently by appending the
domain name and dataNode name to the property name, like:

binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_URL_PROPERTY +
".MyDomain.MyDataNode", "jdbc:postgresql://localhost/mydb");

The specific url value or driver value you are using doesn't have to be
hard coded.  You can read it from a file or from the system properties set
on the command line - whatever you want.


On Tue, Apr 23, 2013 at 7:05 AM, Juan José Gil <> wrote:

> Hi, I'm using cayenne as persistence layer.
> The project is builded with maven and developed with Eclipse.
> The DB is migrated using flyway ( and I'm using
> different DBs config for:
>  * production
>  * development
>  * testing
> So, for migrations, deployment, continuous integration and anything that
> relies on maven I'm using maven "filtering" capabilities to define the jdbc
> url of the database to be used.
> BUT when I'm working at eclipse, and try to run my tests / startup my
> webapp, I cant filter the project resources (not automatically at least)
> So currently I'm copy-pasting my cayenne conf from src/main/resources/db to
> src/test/resources/db... and I'm not happy with this solution, I feel it
> smelly, propense to failure, it's ugly, very ugly!
> I did try to only define the cayenne config at testing resources, but when
> I do that, it doesn't find the mapping xml.
> Is there a way con pass the mapping path instead of a mapping name to a
> cayenne config?
> Can someone point me what should be done to avoid this code/conf smell?

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message