Hi Juan,

As you've discovered, adding/removing relationships require the Cayenne
objects to be registered in an ObjectContext (typically a DataContext).
Generally you'll create and register your objects in an OC using:

DocumentoInventario documentoInventario = objectContext.newObject(
DocumentoInventario.class);

although you can register them separately:

DocumentoInventario documentoInventario = new DocumentoInventario();
objectContext.registerNewObject(documentoInventario);

mrg


On Fri, Apr 8, 2016 at 7:30 PM, Juan Manuel Diaz Lara <
jmdia...@yahoo.com.invalid> wrote:

> I am using Cayenne 4.0.M3.
> I want to build an graph of persistent objects  using the api for many
> targets, but I get the following trace:
> Exception in thread "main" java.lang.NullPointerException
>     at
> org.apache.cayenne.CayenneDataObject.addToManyTarget(CayenneDataObject.java:248)
>     at
> com.ace.pcexpress.pos.model.auto._DocumentoInventario.addToDetalle(_DocumentoInventario.java:92)
>     at
> org.example.cayenne.Main.setupNewDocumentoInventarioWithNewProduct(Main.java:350)
>     at org.example.cayenne.Main.main(Main.java:80)
> Which relevan line on cayenne code is:
>         getObjectContext().propertyChanged(this, relName, null, value);
> this fails because the source object is transient (so, does not have an
> objectcontex). The same happens with removeToManyTarget. Atte. Juan Manuel
> Díaz Lara

Reply via email to