isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Haywood <>
Subject Re: NullPointerException when trying to persist a domain entity
Date Tue, 10 Sep 2013 18:51:18 GMT
How did you instantiate the transient object?  Did you just new it up, or
did you use container.newTransientInstance()?

I'm *hoping* the former.  The right thing to do is the latter.

If the above doesn't sort it out, then could you restate the problem but
using some different class names.  I got a bit confused with your
description, which class is the persistable entity (cf Customer), which
class is the domain service (cf CustomerRepo).

I agree that we should improve the error messages here.  We might even try
to automatically recover from the situation (by creating the adapter lazily
if not present) if we are passed a pojo that was created "outside" of the
container.  Off the top of my head, I can't see why that won't work (but I
might be forgetting something).


On 10 September 2013 19:08, Jeremy Gurr <> wrote:

> I'm getting this when trying to run a test I'm making:
> java.lang.NullPointerException
> at
> at
> org.apache.isis.applib.AbstractContainedObject.persist(
> 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

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