[CDO] references between different packages / DanglingReferenceException [message #1451758] |
Fri, 24 October 2014 08:48 |
Johannes Schaefer Messages: 7 Registered: October 2014 |
Junior Member |
|
|
Hello,
I'm currently working on a implementation to write our models into a CDO storage. The models are generated out of a database which contains our current meta model (no emf).
The current code generates different packages and between classes of this packages are references.
E.g.
<eStructuralFeatures xsi:type="ecore:EReference" name="SELECTED" lowerBound="1" upperBound="-1">
<eAnnotations source="Configurations">
<contents xsi:type="common:CompositeConfiguration">
<children xsi:type="common:PdoPropertyConfiguration"/>
<children xsi:type="configurations_1:DataAccessPropertyConfiguration" ColumnName="Selected Materials">
<ColumnNames>Selected Materials</ColumnNames>
</children>
<children xsi:type="common:MeasureConfiguration" visible="true"/>
</contents>
</eAnnotations>
<eType xsi:type="ecore:EClass" href="mda:www.xxx.de#[ecore::EClass]metalsgui_sample_matmanagement::MAT_VD"/>
</eStructuralFeatures>
metalsgui_sample_matmanagement is a different package than the current.
Now I have problems to write it to a CDO storage. I always get an DanglingReferenceException (The object "org.eclipse.emf.ecore.impl.EClassImpl@618ea67a (eProxyURI: mda:www.xxx.de#[ecore::EClass]metalsgui_sample_matmanagement::MAT_VD)(org.eclipse.emf.ecore.impl.EClassImpl)" is not contained in a resource).
Here is my test code (getContents() returns the current model):
private void loadToCdo2()
{
CDOModelStorage cdo = new CDOModelStorage( "CDO", "localhost", 2036, false, 1000, "" );
try
{
CDOTransaction tx = cdo.getSession().openTransaction();
CDOResource res = tx.getResource( "abc3" );
while( getContents().size() > 0 )
{
EObject obj = getContents().get( 0 );
// EcoreUtil.resolveAll( obj );
log.info( "copy: " + obj + " class: " + obj.getClass() );
res.getContents().add( obj );
}
tx.commit();
}
catch( Exception e )
{
log.warn( "Can't copy (" + e.getMessage() + ")\n", e );
}
log.info( "finish" );
}
Even when I try to resolve (EcoreUtil.resolveAll( obj )) the model I get an exception.
I also tried to write back my models to xmi files (this works) and load it into the cdo via the CDO Explorer in Eclipse. There I get the same DanglingReferenceException.
Now, I don't know how to handle such references between the models. Any suggestion?
Regards,
Johannes.
|
|
|
Re: [CDO] references between different packages / DanglingReferenceException [message #1471466 is a reply to message #1451758] |
Thu, 13 November 2014 05:13 |
|
Hi Johannes,
A DanglingReferenceException means that you try to commit an object A that has a cross-reference to an object B and that
B is not contained in any resource. If that's the case it doesn't matter what client parts of CDO you use, you must find
and fix that problem in your model/application. Even in a pure EMF application (without any CDO) you would get the same
or a similöar exception when you attempt to save it to XML.
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Am 24.10.2014 um 14:54 schrieb Johannes Schaefer:
> Hello,
>
> I'm currently working on a implementation to write our models into a CDO storage. The models are generated out of a
> database which contains our current meta model (no emf).
> The current code generates different packages and between classes of this packages are references.
> E.g.
> <eStructuralFeatures xsi:type="ecore:EReference" name="SELECTED" lowerBound="1" upperBound="-1">
> <eAnnotations source="Configurations">
> <contents xsi:type="common:CompositeConfiguration">
> <children xsi:type="common:PdoPropertyConfiguration"/>
> <children xsi:type="configurations_1:DataAccessPropertyConfiguration" ColumnName="Selected Materials">
> <ColumnNames>Selected Materials</ColumnNames>
> </children>
> <children xsi:type="common:MeasureConfiguration" visible="true"/>
> </contents>
> </eAnnotations>
> <eType xsi:type="ecore:EClass" href="mda:www.xxx.de#[ecore::EClass]metalsgui_sample_matmanagement::MAT_VD"/>
> </eStructuralFeatures>
>
> metalsgui_sample_matmanagement is a different package than the current.
>
> Now I have problems to write it to a CDO storage. I always get an DanglingReferenceException (The object
> "mailto:org.eclipse.emf.ecore.impl.EClassImpl@618ea67a (eProxyURI:
> mda:www.xxx.de#[ecore::EClass]metalsgui_sample_matmanagement::MAT_VD)(org.eclipse.emf.ecore.impl.EClassImpl)" is not
> contained in a resource).
>
> Here is my test code (getContents() returns the current model):
> private void loadToCdo2()
> {
> CDOModelStorage cdo = new CDOModelStorage( "CDO", "localhost", 2036, false, 1000, "" );
> try
> {
> CDOTransaction tx = cdo.getSession().openTransaction();
> CDOResource res = tx.getResource( "abc3" );
> while( getContents().size() > 0 )
> {
> EObject obj = getContents().get( 0 );
> // EcoreUtil.resolveAll( obj );
> log.info( "copy: " + obj + " class: " + obj.getClass() );
> res.getContents().add( obj );
> }
> tx.commit();
> }
> catch( Exception e )
> {
> log.warn( "Can't copy (" + e.getMessage() + ")\n", e );
> }
> log.info( "finish" );
> }
>
> Even when I try to resolve (EcoreUtil.resolveAll( obj )) the model I get an exception.
>
> I also tried to write back my models to xmi files (this works) and load it into the cdo via the CDO Explorer in
> Eclipse. There I get the same DanglingReferenceException.
>
> Now, I don't know how to handle such references between the models. Any suggestion?
>
> Regards,
> Johannes.
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Powered by
FUDForum. Page generated in 0.03199 seconds