isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Gurr <jere...@infusionsoft.com>
Subject NullPointerException when trying to persist a domain entity
Date Tue, 10 Sep 2013 18:08:02 GMT
I'm getting this when trying to run a test I'm making:

java.lang.NullPointerException
at org.apache.isis.core.metamodel.services.container.DomainObjectContainerDefault.persist(DomainObjectContainerDefault.java:243)
at org.apache.isis.applib.AbstractContainedObject.persist(AbstractContainedObject.java:278)

These line numbers are from a fresh pull performed this morning, so it's likely they will
still be correct if you are looking at the head of the master branch.

I'm sure I've misconfigured something, but I'm trying to understand what's happening here
so I can fix it. It would also be nice if nulls were checked for in this part of code and
a more useful error message thrown. Here is the code throwing the exception:

    @Override
    public void persist(final Object transientObject) {
        final ObjectAdapter adapter = getAdapterManager().getAdapterFor(transientObject);
        // TODO check aggregation is supported
        if (adapter.isParented()) {
            return;
        }

In this case, the adapter is null, and so the isParented method is called on a null object,
throwing the exception.

The transientObject being passed in here is an instance of my model class named ServiceClass.
The service class which contains methods to create new instances and perform various searches
is called ServiceClassService (analogous to TodoItems). I stepped through this code and can
see the map it is looking in for the getAdapterFor method contains the services I registered,
and so it could look up ServiceClassService, but not ServiceClass. But I'm trying to persist
a data entity (ServiceClass), so I'm not sure what's supposed to be happening here.

I have a class which extends AbstractFactoryAndRepository which of course has a persist method.
I call that method to persist a newly created transient entity, but this exception is thrown.
Persist seems to be the method I'm looking for, but why does it look to the service list to
find which adapter to use to persist the entity? And how do I either get the correct service
registered, or change the ServiceClassService so that it recognizes the ServiceClass entity
as something it can work with? Sorry this probably doesn't make much sense, because I don't
quite understand what the persistence code is trying to do here. Any help would be greatly
appreciated :)

-- Jeremy

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message