Skip to main content



      Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » NullPointer exception when using Elver/Teneo's HibernateResource (with solution)
NullPointer exception when using Elver/Teneo's HibernateResource (with solution) [message #50908] Mon, 18 September 2006 18:12 Go to next message
Eclipse UserFriend
Originally posted by: sprakash.tibco.com

Martin,

I used Elver/Teneo's (0.7.2) HibernateResource to execute a Hibernate
query. I get the following NPE:

Exception in thread "main" java.lang.NullPointerException
at
org.elver.store.resource.StoreResource.attachedHelper(StoreR esource.java:456)
at org.elver.store.resource.StoreResource.attached(StoreResourc e.java:414)
at org.elver.store.resource.StoreResource.load(StoreResource.ja va:245)


I do not get the NPE if I use Hibernate sessions directly i.e. the query
executes just fine. The NPE gets resolved if I add a null check in the
following method of org.elver.store.resource.StoreResource.java (Is this a
valid fix?):


protected void attachedHelper(EObject eObject) {
// a bit strange as an object can only be contained once but this can
happen if someone
// adds an object to a resource directly and then later add this same
object as a child
// to a container
if (eObject == null) return; /* Inserted null check */
if (newEObjects.contains(eObject) || loadedEObjects.contains(eObject))
return;

addedEObject(eObject);

if (isTrackingModification()) {
eObject.eAdapters().add(modificationTrackingAdapter);
}

Map map = getIntrinsicIDToEObjectMap();
if (map != null) {
String id = EcoreUtil.getID(eObject);
if (id != null) {
map.put(id, eObject);
}
}

if (eObject instanceof InternalEObject && eObject.eResource() == null) {
StoreUtil.setEResource((InternalEObject)eObject, this);
}

// now also attach all ereferences with single values
for (Iterator it = eObject.eClass().getEAllReferences().iterator();
it.hasNext();) {
final EReference eref = (EReference)it.next();
if (!eref.isMany() && eObject.eGet(eref) != null) { // the ismanies are
handled differently
final Resource res = ((EObject)eObject.eGet(eref)).eResource();
if (res == null) { // attach it to this resource because it has no
other
attached((EObject)eObject.eGet(eref));
}
}
}
}
Re: NullPointer exception when using Elver/Teneo's HibernateResource (with solution) [message #50965 is a reply to message #50908] Tue, 19 September 2006 00:41 Go to previous message
Eclipse UserFriend
Hi Sundeep,
I am not sure but can you check where the null eobject and npe actually comes from?

As far as I can see the attachedhelper gets the result of an iterator. It seems that the iterator
next statement returns null, although there is a hasNext check.

In the source code I have line 456 is this:
final EReference eref = (EReference)it.next();

gr. Martin

Sundeep Prakash wrote:
> Martin,
>
> I used Elver/Teneo's (0.7.2) HibernateResource to execute a Hibernate
> query. I get the following NPE:
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.elver.store.resource.StoreResource.attachedHelper(StoreR esource.java:456)
>
> at
> org.elver.store.resource.StoreResource.attached(StoreResourc e.java:414)
> at org.elver.store.resource.StoreResource.load(StoreResource.ja va:245)
>
>
> I do not get the NPE if I use Hibernate sessions directly i.e. the query
> executes just fine. The NPE gets resolved if I add a null check in the
> following method of org.elver.store.resource.StoreResource.java (Is this
> a valid fix?):
>
>
> protected void attachedHelper(EObject eObject) {
> // a bit strange as an object can only be contained once but
> this can happen if someone
> // adds an object to a resource directly and then later add this
> same object as a child
> // to a container
> if (eObject == null) return; /* Inserted null check */
> if (newEObjects.contains(eObject) ||
> loadedEObjects.contains(eObject)) return;
>
> addedEObject(eObject);
>
> if (isTrackingModification()) {
> eObject.eAdapters().add(modificationTrackingAdapter);
> }
>
> Map map = getIntrinsicIDToEObjectMap();
> if (map != null) {
> String id = EcoreUtil.getID(eObject);
> if (id != null) {
> map.put(id, eObject);
> }
> }
>
> if (eObject instanceof InternalEObject && eObject.eResource() ==
> null) {
> StoreUtil.setEResource((InternalEObject)eObject, this);
> }
>
> // now also attach all ereferences with single values
> for (Iterator it =
> eObject.eClass().getEAllReferences().iterator(); it.hasNext();) {
> final EReference eref = (EReference)it.next();
> if (!eref.isMany() && eObject.eGet(eref) != null) { // the
> ismanies are handled differently
> final Resource res =
> ((EObject)eObject.eGet(eref)).eResource();
> if (res == null) { // attach it to this resource because
> it has no other
> attached((EObject)eObject.eGet(eref));
> }
> }
> }
> }
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: NullPointer exception when using Elver/Teneo's HibernateResource (with solution) [message #591358 is a reply to message #50908] Tue, 19 September 2006 00:41 Go to previous message
Eclipse UserFriend
Hi Sundeep,
I am not sure but can you check where the null eobject and npe actually comes from?

As far as I can see the attachedhelper gets the result of an iterator. It seems that the iterator
next statement returns null, although there is a hasNext check.

In the source code I have line 456 is this:
final EReference eref = (EReference)it.next();

gr. Martin

Sundeep Prakash wrote:
> Martin,
>
> I used Elver/Teneo's (0.7.2) HibernateResource to execute a Hibernate
> query. I get the following NPE:
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.elver.store.resource.StoreResource.attachedHelper(StoreR esource.java:456)
>
> at
> org.elver.store.resource.StoreResource.attached(StoreResourc e.java:414)
> at org.elver.store.resource.StoreResource.load(StoreResource.ja va:245)
>
>
> I do not get the NPE if I use Hibernate sessions directly i.e. the query
> executes just fine. The NPE gets resolved if I add a null check in the
> following method of org.elver.store.resource.StoreResource.java (Is this
> a valid fix?):
>
>
> protected void attachedHelper(EObject eObject) {
> // a bit strange as an object can only be contained once but
> this can happen if someone
> // adds an object to a resource directly and then later add this
> same object as a child
> // to a container
> if (eObject == null) return; /* Inserted null check */
> if (newEObjects.contains(eObject) ||
> loadedEObjects.contains(eObject)) return;
>
> addedEObject(eObject);
>
> if (isTrackingModification()) {
> eObject.eAdapters().add(modificationTrackingAdapter);
> }
>
> Map map = getIntrinsicIDToEObjectMap();
> if (map != null) {
> String id = EcoreUtil.getID(eObject);
> if (id != null) {
> map.put(id, eObject);
> }
> }
>
> if (eObject instanceof InternalEObject && eObject.eResource() ==
> null) {
> StoreUtil.setEResource((InternalEObject)eObject, this);
> }
>
> // now also attach all ereferences with single values
> for (Iterator it =
> eObject.eClass().getEAllReferences().iterator(); it.hasNext();) {
> final EReference eref = (EReference)it.next();
> if (!eref.isMany() && eObject.eGet(eref) != null) { // the
> ismanies are handled differently
> final Resource res =
> ((EObject)eObject.eGet(eref)).eResource();
> if (res == null) { // attach it to this resource because
> it has no other
> attached((EObject)eObject.eGet(eref));
> }
> }
> }
> }
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:Teneo: Hibernate 3.2rc4 incompatibility
Next Topic:Re: Ecore to DBSchema...Is sympedia's CDO same as the one in EMFT now
Goto Forum:
  


Current Time: Fri May 09 14:25:08 EDT 2025

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

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

Back to the top