persistence@glassfish.java.net

Re: Cannot see newly created object

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Mon, 30 Jun 2008 09:53:57 -0400

This is not a cascading issue. If it were a cascading issue then the
child objects would not exist in the database and the restart would not
resolve the issue.
There is no need to merge the parent as the parent is already managed.

The issue here is most likely that the Persistence Context used to read
the Parent and Children is extended (or part of an existing transaction)
and therefore without a refresh does not have access to the latest
data. Reading in a new transaction, clearing the Peristence Context or
refreshing the Parent object should resolve the issue.
--Gordon

Gary Jacobson wrote:
> Seems like a cascading issue. Check whether you have cascading enabled
> in your ChildEntity.parent ManyToOne annotation. Or you could merge
> the parent rather than persisting the child, and ensure that the
> ParentEntity.children OneToMany annotation has cascading enabled.
>
> If this doesn't work or you don't want to use cascading, try merging
> the parent after persisting the child.
>
> It probably worked in another case because there was no caching, or
> the cache was being bypassed.
>
> On Mon, Jun 30, 2008 at 2:43 PM,
> <persistence-digest-help_at_glassfish.dev.java.net
> <mailto:persistence-digest-help_at_glassfish.dev.java.net>> wrote:
>
>
>
>
> ---------- Forwarded message ----------
> From: Gordon Yorke <gordon.yorke_at_oracle.com
> <mailto:gordon.yorke_at_oracle.com>>
> To: persistence_at_glassfish.dev.java.net
> <mailto:persistence_at_glassfish.dev.java.net>
> Date: Mon, 30 Jun 2008 08:21:36 -0400
> Subject: Re: Cannot see newly created object
> Hello Markus
> What are the transactional boundaries for the listening SB?
> Is the em you are accessing in the listener in a transaction and
> reading transactional data?
> --Gordon
>
> Markus KARG wrote:
>
> I forgot to mention: Exactly the same code executed from
> within a session bean results in the new child beeing listed
> correctly.
>
> So what difference is between a MDB and a SB?
>
> Thanks! :-)
> Markus
>
> Markus Karg schrieb:
>
> I have a strange problem and need your kind help. :-)
>
>
> In GlassFishv2ur2, I am running a session bean that does:
>
> parent = em.find(ParentEntity.class, 1000).getSingleResult();
> parent.getChildren();
>
> which lists the content of a OneToMany relationship.
>
> Now a message driven bean does:
>
> parent = em.find(ParentEntity.class, 1000).getSingleResult();
> child = new ChildEntity(parent); // Implicitly sets "One"-Side
> parent.getChildren().add(child); // Explicitly sets
> "Many"-Side
> em.persist(child);
>
> When I go to the DBMS, I can see the row of the new child
> including all fields. The child is correctly linked with
> the parent.
>
> But when running the listing again:
>
> parent = em.find(ParentEntity.class, 1000).getSingleResult();
> parent.getChildren();
>
> Then still I do not see the new child. To make it appear,
> I must undeploy and deploy. That is very weird, since it
> can be seen in the database table, and I have set both
> sides of the relationship as you can see in the code snippet.
>
> Looks like a cache problem, but I just do not understand
> how to solve it.
>
> Has anybody an idea what the cause is and how to get rid
> of it?
>
> Thanks a lot! :-)
> Markus
>
> QUIPSY QUALITY GmbH & Co. KG
> Ein Unternehmen der MES-Gruppe
> Stuttgarter Strasse 23
> D-75179 Pforzheim
> Tel: 07231-9189-52
> Fax: 07231-9189-59
> www.quipsy.de <http://www.quipsy.de>
> karg_at_quipsy.de <mailto:karg_at_quipsy.de>
> Registergericht Mannheim HRA 701214
> Geschäftsführer: Nils Schroeder
>
> Diese E-Mail enthält persönliche, vertrauliche und vor
> Weitergabe geschützte Informationen und ist ausschließlich
> für den vorgesehenen o.g. Empfänger (Adressaten) bestimmt.
> Falls Sie diese E-Mail versehentlich erhalten haben und
> nicht der vorgesehene Empfänger sind, bitten wir Sie, die
> E-Mail und deren Anhänge nicht aufzubewahren, nicht zu
> vervielfältigen, nicht zu nutzen und nicht weiterzugeben.
> Bitte informieren Sie uns als Absender über diesen
> Zustellungsfehler und löschen Sie die E-Mail.
>
>
>
>
>
>
>
>
>
>
>
>