users@glassfish.java.net

Re: Stateful Session detaches entity?

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Wed, 04 Jun 2008 14:03:10 -0700

Right. This is the spec refs:

3.3 Persistence Context Lifetime
By default, the lifetime of the persistence context of a container-managed
entity manager corresponds to the scope of a transaction (i.e., it is of type
PersistenceContextType.TRANSACTION).

3.3.1 Transaction Commit
The managed entities of a transaction-scoped persistence context become detached
when the transaction commits; the managed entities of an extended persistence
context remain managed.

HTH,
-marina

Markus Karg wrote:
> Meanwhile I found the solution: I have to use @PersistenceContext(type =
> EXTENDED) to make the entity manager survive the end of the transaction
> or I need to do this.entity = this.em.merge(this.entity) inside of
> @AroundInvoke. Both works pretty well.
>
>
>
> Regards
>
> Markus
>
>
>
> *From:* Markus Karg [mailto:karg_at_quipsy.de]
> *Sent:* Mittwoch, 4. Juni 2008 11:05
> *To:* users_at_glassfish.dev.java.net
> *Subject:* Stateful Session detaches entity?
>
>
>
> In my stateful session bean, I store a JPA entity found by em.find() in
> a member. In the business methods, I want to use that entity. But
> TopLink tells me that the entity is detached. The entity manager used
> always is the same (member annotated by @PersistenceContext).
>
>
>
> I am not sure whether this is a bug or whether some specification (which
> one?) says that an entity must become detached between to calls to a
> STATEFUL (!) session bean.
>
>
>
> Any ideas?
>
>
>
> Thanks
>
> 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.
>
>
>