Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Fetching a CDO object by CDOID
Fetching a CDO object by CDOID [message #425566] Mon, 01 December 2008 16:55 Go to next message
Anders Forsell is currently offline Anders ForsellFriend
Messages: 127
Registered: July 2009
Senior Member
Hi,

I am trying to fetch a CDO object by using the CDOID. I have understood
that the CDOID is unique within a repository and I thought the following
would work:

// A session has been created pointing to a repository where an
object with a CDOID is residing
// cdoID is the long id value of the CDO object
CDOTransaction trans = session.openTransaction();
CDOID id = new CDOIDLongImpl(cdoID);
CDOObject cdoobj = ((CDOView) trans).getObject(id);

I get a NPE caused by CDOObjectImpl.class # getCDOView returning null:

static CDOViewImpl getCDOView(InternalCDOObject cdoObject)
{
CDOResource resource = cdoObject.cdoResource();
return resource != null ?
(CDOViewImpl)cdoObject.cdoResource().cdoView() : null;
}

.... because the cdoObject.cdoResource() returns null.

Is this a bug, or do I have to load the model containing the object first?

---
Anders

Part of the stack trace:

java.lang.NullPointerException
at
org.eclipse.emf.internal.cdo.CDOObjectImpl.cdoInternalSetVie w(CDOObjectImpl.java:171)
at
org.eclipse.emf.internal.cdo.CDOViewImpl.createProxy(CDOView Impl.java:434)
at org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:333)
at org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:305)
at org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:1)
Re: Fetching a CDO object by CDOID [message #425567 is a reply to message #425566] Mon, 01 December 2008 17:02 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
Based on the stack trace I assume you are using 1.0.x. Right?

CAn I know which minor versionof CDO you are using ... 1.0.0 or 1.0.1 or
1.0.2 or 1.0.3 or 1.0.4 :-)

Also what is the type of the object you try to retrieved... (Resource..
or any other objects) ?

Can you put the full stack trace ?


It will not change anything but using

CDOID id = CDOIDUtil.createLong(cdoID);
instead of
CDOID id = new CDOIDLongImpl(cdoID);

would be better!!:-) (But it will not change anything)

Meanwhile can you try to put loadDemand = true

CDOObject cdoobj = ((CDOView) trans).getObject(id, >>>true<<<);



Simon



Anders Forsell wrote:
> Hi,
>
> I am trying to fetch a CDO object by using the CDOID. I have understood
> that the CDOID is unique within a repository and I thought the following
> would work:
>
> // A session has been created pointing to a repository where an
> object with a CDOID is residing
> // cdoID is the long id value of the CDO object
> CDOTransaction trans = session.openTransaction();
> CDOID id = new CDOIDLongImpl(cdoID);
> CDOObject cdoobj = ((CDOView) trans).getObject(id);
>
> I get a NPE caused by CDOObjectImpl.class # getCDOView returning null:
>
> static CDOViewImpl getCDOView(InternalCDOObject cdoObject)
> {
> CDOResource resource = cdoObject.cdoResource();
> return resource != null ?
> (CDOViewImpl)cdoObject.cdoResource().cdoView() : null;
> }
>
> ... because the cdoObject.cdoResource() returns null.
>
> Is this a bug, or do I have to load the model containing the object first?
>
> ---
> Anders
>
> Part of the stack trace:
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.internal.cdo.CDOObjectImpl.cdoInternalSetVie w(CDOObjectImpl.java:171)
>
> at
> org.eclipse.emf.internal.cdo.CDOViewImpl.createProxy(CDOView Impl.java:434)
> at
> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:333)
> at
> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:305)
> at
> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:1)
Re: Fetching a CDO object by CDOID [message #425573 is a reply to message #425567] Mon, 01 December 2008 19:33 Go to previous message
Anders Forsell is currently offline Anders ForsellFriend
Messages: 127
Registered: July 2009
Senior Member
The loadDemand=true made the trick.

Thanks!

---
Anders

Simon McDuff wrote:
> Based on the stack trace I assume you are using 1.0.x. Right?
>
> CAn I know which minor versionof CDO you are using ... 1.0.0 or 1.0.1 or
> 1.0.2 or 1.0.3 or 1.0.4 :-)
>
> Also what is the type of the object you try to retrieved... (Resource..
> or any other objects) ?
>
> Can you put the full stack trace ?
>
>
> It will not change anything but using
>
> CDOID id = CDOIDUtil.createLong(cdoID);
> instead of
> CDOID id = new CDOIDLongImpl(cdoID);
>
> would be better!!:-) (But it will not change anything)
>
> Meanwhile can you try to put loadDemand = true
>
> CDOObject cdoobj = ((CDOView) trans).getObject(id, >>>true<<<);
>
>
>
> Simon
>
>
>
> Anders Forsell wrote:
>> Hi,
>>
>> I am trying to fetch a CDO object by using the CDOID. I have
>> understood that the CDOID is unique within a repository and I thought
>> the following would work:
>>
>> // A session has been created pointing to a repository where an
>> object with a CDOID is residing
>> // cdoID is the long id value of the CDO object
>> CDOTransaction trans = session.openTransaction();
>> CDOID id = new CDOIDLongImpl(cdoID);
>> CDOObject cdoobj = ((CDOView) trans).getObject(id);
>>
>> I get a NPE caused by CDOObjectImpl.class # getCDOView returning null:
>>
>> static CDOViewImpl getCDOView(InternalCDOObject cdoObject)
>> {
>> CDOResource resource = cdoObject.cdoResource();
>> return resource != null ?
>> (CDOViewImpl)cdoObject.cdoResource().cdoView() : null;
>> }
>>
>> ... because the cdoObject.cdoResource() returns null.
>>
>> Is this a bug, or do I have to load the model containing the object
>> first?
>>
>> ---
>> Anders
>>
>> Part of the stack trace:
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.emf.internal.cdo.CDOObjectImpl.cdoInternalSetVie w(CDOObjectImpl.java:171)
>>
>> at
>> org.eclipse.emf.internal.cdo.CDOViewImpl.createProxy(CDOView Impl.java:434)
>>
>> at
>> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:333)
>> at
>> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:305)
>> at
>> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:1)
Previous Topic:[CDO] NPE when removing an object in containment tree
Next Topic:OrderBy example?
Goto Forum:
  


Current Time: Fri Apr 26 02:55:43 GMT 2024

Powered by FUDForum. Page generated in 0.03102 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top