Hi there,
Looks like a static Configuration singleton is causing a problem.
Could you just keep 2 Configurations separate and avoid using
'initializeSharedConfiguration'. E.g.:
Configuration conf = ...;
conf.initialize();
// store conf reference for later use
...
// use a stored conf to create the context:
DataContext context = conf.getDomain().createDataContext();
Hope this helps.
Andrus
On Sep 3, 2009, at 6:56 PM, Cristiano Ghersi wrote:
> Good morning,
>
>
>
> I've got a problem using the static method
> DataContext.createDataContext();
>
>
>
> My environment is the following: I've got a library (let's call it
> "DataLayer") which use cayenne for the communication towards a
> single DB.
>
> In this library a class called DbManager create a DataContext in its
> constructor using this piece of code:
>
>
>
> try {
>
> String pathWithConfigurationFiles = "/home/matteo/config/cayenne";
>
> org.apache.cayenne.conf.Configuration conf = new
> FileConfiguration("cayenne.xml");
>
>
>
> // Cayenne configuration files can be found at this location
>
> ((FileConfiguration) conf).addFilesystemPath(new
> File(pathWithConfigurationFiles));
>
> org
> .apache
> .cayenne.conf.Configuration.initializeSharedConfiguration(conf);
>
> } catch (Exception e){
>
> e.printStackTrace();
>
> }
>
>
>
> // Create a new one
>
> context = DataContext.createDataContext();
>
>
>
>
>
> This library is used by two different bundles (OSGi Framework);
> let's call
> these bundles Bundle1 and Bundle2.
>
>
>
> If I use only one of these bundles all goes perfectly well, but if I
> try to
> start Bundle2 when Bundle1 is already started, the following error
> appears
> and Bundle2 is stopped:
>
>
>
> INFO: loading <node name='PacketNode'
> datasource='PacketNode.driver.xml'
> factory='org.apache.cayenne.conf.DriverDataSourceFactory'
> schema-update-
> strategy='org.apache.cayenne.access.dbsync.SkipSchemaUpdateStr
> ategy'>.
>
> org.apache.cayenne.ConfigurationException: [v.3.0M6 May 18 2009
> 07:49:46]
> Error during Configuration initialization.
> org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy cannot be
> cast to
> org.apache.cayenne.access.dbsync.SchemaUpdateStrategy
>
> at
> org
> .apache
> .cayenne.conf.Configuration.initializeSharedConfiguration(Configur
> ation.java:168)
>
> at dbManager.DbManager.<init>(DbManager.java:58)
>
> at
> zzz_bundledbquery.DBQueryStarter.start(DBQueryStarter.java:20)
>
> at
> org.eclipse.osgi.framework.internal.core.BundleContextImpl
> $1.run(BundleConte
> xtImpl.java:782)
>
> at java.security.AccessController.doPrivileged(Native
> Method)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.BundleContextImpl.startActivator(Bu
> ndleContextImpl.java:773)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.BundleContextImpl.start(BundleConte
> xtImpl.java:754)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.BundleHost.startWorker(BundleHost.j
> ava:352)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.AbstractBundle.start(AbstractBundle
> .java:280)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.AbstractBundle.start(AbstractBundle
> .java:272)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.FrameworkCommandProvider._start(Fra
> meworkCommandProvider.java:253)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
>
> at
> sun
> .reflect
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
> )
>
> at
> sun
> .reflect
> .DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
> .java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:597)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.FrameworkCommandInterpreter.execute
> (FrameworkCommandInterpreter.java:155)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.FrameworkConsole.docommand(Framewor
> kConsole.java:303)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.FrameworkConsole.console(FrameworkC
> onsole.java:288)
>
> at
> org
> .eclipse
> .osgi.framework.internal.core.FrameworkConsole.run(FrameworkConso
> le.java:224)
>
> at java.lang.Thread.run(Thread.java:619)
>
> Caused by: java.lang.ClassCastException:
> org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy cannot be
> cast to
> org.apache.cayenne.access.dbsync.SchemaUpdateStrategy
>
> at
> org
> .apache
> .cayenne.conf.RuntimeLoadDelegate.shouldLoadDataNode(RuntimeLoadDe
> legate.java:303)
>
> at
> org.apache.cayenne.conf.ConfigLoader
> $NodeHandler.init(ConfigLoader.java:345)
>
> at
> org.apache.cayenne.conf.ConfigLoader
> $DomainHandler.startElement(ConfigLoader
> .java:222)
>
> at
> com
> .sun
> .org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Ab
> stractSAXParser.java:501)
>
> at
> com
> .sun
> .org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartEl
> ement(XMLNSDocumentScannerImpl.java:400)
>
> at
> com
> .sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl
> $Fragm
> entContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
>
> at
> com
> .sun
> .org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocum
> entScannerImpl.java:648)
>
> at
> com
> .sun
> .org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSD
> ocumentScannerImpl.java:140)
>
> at
> com
> .sun
> .org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanD
> ocument(XMLDocumentFragmentScannerImpl.java:510)
>
> at
> com
> .sun
> .org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Con
> figuration.java:807)
>
> at
> com
> .sun
> .org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Con
> figuration.java:737)
>
> at
> com
> .sun
> .org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:10
> 7)
>
> at
> com
> .sun
> .org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractS
> AXParser.java:1205)
>
> at
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl
> $JAXPSAXParser.parse(SA
> XParserImpl.java:522)
>
> at
> org.apache.cayenne.conf.ConfigLoader.loadDomains(ConfigLoader.java:78)
>
> at
> org
> .apache
> .cayenne.conf.DefaultConfiguration.initialize(DefaultConfiguration
> .java:152)
>
> at
> org
> .apache
> .cayenne.conf.Configuration.initializeSharedConfiguration(Configur
> ation.java:159)
>
> ... 19 more
>
>
>
>
>
> What I'm missing?
>
>
>
> Thank you very much for the help!!
>
>
>
> Cristiano Ghersi
>
>
>
This archive was generated by hypermail 2.0.0 : Fri Sep 04 2009 - 05:32:19 EDT