Yup. I couldn't find it and wanted to make sure we had a bug for this change.
Good catch
-----Original Message-----
From: Michael.Bouschen_at_Sun.COM [mailto:Michael.Bouschen_at_Sun.COM]On
Behalf Of Michael Bouschen
Sent: Wednesday, May 17, 2006 2:56 PM
To: Peter Krogh
Cc: persistence_at_glassfish.dev.java.net
Subject: Re: [Issue 666] New - EMF can be garbage collected if they are
not held on to.
Hi Peter,
is this a duplicate of issue 662 I filed last week and Tom resolved
after checking in the fix?
https://glassfish.dev.java.net/issues/show_bug.cgi?id=662
Regards Michael
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=666
> Issue #|666
> Summary|EMF can be garbage collected if they are not held on t
> |o.
> Component|glassfish
> Version|9.0pe
> Platform|All
> OS/Version|All
> URL|
> Status|NEW
> Status whiteboard|
> Keywords|
> Resolution|
> Issue type|DEFECT
> Priority|P2
> Subcomponent|entity-persistence
> Assigned to|mvatkina
> Reported by|pkrogh
>
>
>
>
>
>
> ------- Additional comments from pkrogh_at_dev.java.net Wed May 17 15:52:14 +0000 2006 -------
> From Michael B.
>
> the recent persistence drop adds a finalize method to the EMF
> implementation in entity-persistence module. This closes the EMF which
> then closes all open EMs created by this factory. With this change my
> simple J2SE test case runs into an IllegalStateException saying
> "Attempting to execute an operation on a closed EntityManager." when
> creating a new query instance.
>
> The reason is that I used the following pattern to create an EM:
> EntityManager em =
> Persistence.createEntityManagerFactory("pu").createEntityManager();
> Please note, I do not keep a reference to the EMF. Since the EM does not
> hold a strong reference to the EMF, the garbage collector can remove the
> EMF instance which then in turn closes the EM that is still used by the
> application.
>
> I'm not recommending this code pattern. However, to avoid the above
> scenario I propose the EM implementation should hold a strong reference
> to its factory. Then the factory cannot be garbage collected as long as
> as there is an EM around created by this factory.
>
> What do you think? Do you want me to create a glassfish issue for this?
>
> Attached you find a jar including a single test case that can be used to
> reproduce the problem. You need to adapt the properties in build.xml and
> persistence.xml to your local environment and then call 'ant'.
>
> Regards Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: issues-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: issues-help_at_glassfish.dev.java.net
>