You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Sukanya Ratanotoyanon <sr...@gmail.com> on 2007/11/08 04:47:37 UTC

Question about using a library having Cayenne embedded within a project using Cayenne

Hello,

I'm having a problem getting a correct DataDomain when I'm using a library
containing cayenne objects. Basically, I'm working on a project using
Cayenne. I need the database URL, usename and password to be configurable.
Therefore, I have this method to set up them up like this:

            Configuration config = Configuration.getSharedConfiguration();

            DataDomain domain = config.getDomain();
            DataNode cNode = domain.getNode(LINK_DB_NODE);
            ....
            ....

 I received a library that also uses Cayenne to map the database, and tried
to integrate this library into my project. However, after integration, when
I call Configuration.getSharedConfiguration(), it loads the configuration
from the cayenne.xml in the library instead of the one I'm using for the
project. So when I tried to get my DataNode, it cannot be founded. This
results in NullPointerException when I use my DataNode object. Is there a
way to work around this, or do I miss something? I just start using Cayenne
not very long ago and  would appreciate any helps.

Thank you very much,
Sukanya

Re: Question about using a library having Cayenne embedded within a project using Cayenne

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Sukanya,

The simplest way to resolve such conflicts is to avoid place  
cayenne.xml in the root of the jar (place it in a package  
subdirectory instead). And then instantiate a separate Configuration  
for each cayenne.xml instead of using a shared one:

http://cayenne.apache.org/doc/customizing-configuration.html


DefaultConfiguration c1 = new DefaultConfiguration();			
c1.addClassPath("my/package/conf1");
c1.initialize();

DefaultConfiguration c2 = new DefaultConfiguration();			
c2.addClassPath("my/package/conf2");
c2.initialize();

Andrus



On Nov 7, 2007, at 10:47 PM, Sukanya Ratanotoyanon wrote:

> Hello,
>
> I'm having a problem getting a correct DataDomain when I'm using a  
> library
> containing cayenne objects. Basically, I'm working on a project using
> Cayenne. I need the database URL, usename and password to be  
> configurable.
> Therefore, I have this method to set up them up like this:
>
>             Configuration config =  
> Configuration.getSharedConfiguration();
>
>             DataDomain domain = config.getDomain();
>             DataNode cNode = domain.getNode(LINK_DB_NODE);
>             ....
>             ....
>
>  I received a library that also uses Cayenne to map the database,  
> and tried
> to integrate this library into my project. However, after  
> integration, when
> I call Configuration.getSharedConfiguration(), it loads the  
> configuration
> from the cayenne.xml in the library instead of the one I'm using  
> for the
> project. So when I tried to get my DataNode, it cannot be founded.  
> This
> results in NullPointerException when I use my DataNode object. Is  
> there a
> way to work around this, or do I miss something? I just start using  
> Cayenne
> not very long ago and  would appreciate any helps.
>
> Thank you very much,
> Sukanya