You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Adam Borkowski <bo...@gmail.com> on 2009/11/16 18:16:29 UTC

Is it possible to turn off AutoDetach?

I tried to turn off auto detaching after commit or entity manager closing by
setting 
openjpa.AutoDetach property to "false" or to empty value, but it seems not
to work as I expected.

Is there any possibility to turn AutoDetach off?
I'm using OpenJPA 1.2.1 version.

I know that this behavior is not exactly consistent with JPA standard.

Thanks,
Adam Borkowski


-- 
View this message in context: http://n2.nabble.com/Is-it-possible-to-turn-off-AutoDetach-tp4013250p4013250.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Is it possible to turn off AutoDetach?

Posted by Michael Dick <mi...@gmail.com>.
Hi Michael,

I wouldn't affect the AutoDetach property to affect em.clear(), since that's
a manual detach. Might have worked for you, but I'd be careful about relying
on it. If you're just using that as a proof of concept that's fine though.

Keeping entities attached after the em closes which doesn't make sense to
me. If the EntityManager is closed what could the entities be attached to?
I'd think they would _have_ to be detached in this case.

Detaching after the transaction completes is a different issue. If you're
using an extended scope EntityManager then the entities shouldn't be
detached. If that's the behavior you want, why not switch to use an extended
scope EM? You can probably work around the issue with AutoDetach as a config
property or with the workaround  you mentioned, but extended scope seems a
bit simpler to me.

I suppose if you want to selectively detach you can use a JTA scoped EM with
the AutoDetach property . I'm not sure what the use case for that would be,
but I'm sure someone will come up with one :-)

-mike

On Mon, Nov 16, 2009 at 11:29 AM, Michael Vorburger <
mvorburger@odyssey-group.com> wrote:

> > I tried to turn off auto detaching after commit or entity manager
> closing by setting openjpa.AutoDetach property to "false" or to empty
> value, but it seems not to work as I expected.
>
> Funny to see this email today.. I coincidentally tried this last week as
> well! I got it working on one open EM directly, with this (but read on):
>
>  OpenJPAEntityManager oem = (OpenJPAEntityManager)em;
>  System.out.println(oem.getAutoDetach());
>  EnumSet<AutoDetachType> d = oem.getAutoDetach();
>  d.clear();
>  oem.setAutoDetach(d);
>
> but NOT, whatever I tried, with any config. on the
> EntityManagerFactory...
>
> > I know that this behavior is not exactly consistent with JPA standard.
>
> Exactly; so after a good night's sleep we're not using above, and found
> another solution to our "problem" instead.
>
> PS, if anybody is interested: The problem why we also initially wanted
> to turn off auto detaching for entity manager closing was that the
> http://static.springsource.org/spring/docs/2.0.8/api/org/springframework
> /orm/jpa/SharedEntityManagerCreator.html<http://static.springsource.org/spring/docs/2.0.8/api/org/springframework%0A/orm/jpa/SharedEntityManagerCreator.html>"will fall back to a newly
> created EntityManager per operation" for a non-transactional read, so it
> closes the EM in its Proxy, and thus stuff detaches before you get a
> chance to do anything in between.  We are now going to do what we wanted
> to do before Spring does its close() and implicit detach in a @PostLoad
> instead.
>
>
> -----Original Message-----
> From: Adam Borkowski [mailto:borkos.devel@gmail.com]
> Sent: Monday, November 16, 2009 6:16 PM
> To: users@openjpa.apache.org
> Subject: Is it possible to turn off AutoDetach?
>
>
> I tried to turn off auto detaching after commit or entity manager
> closing by setting openjpa.AutoDetach property to "false" or to empty
> value, but it seems not to work as I expected.
>
> Is there any possibility to turn AutoDetach off?
> I'm using OpenJPA 1.2.1 version.
>
> I know that this behavior is not exactly consistent with JPA standard.
>
> Thanks,
> Adam Borkowski
>
>
> --
> View this message in context:
> http://n2.nabble.com/Is-it-possible-to-turn-off-AutoDetach-tp4013250p401
> 3250.html<http://n2.nabble.com/Is-it-possible-to-turn-off-AutoDetach-tp4013250p401%0A3250.html>
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
> ____________________________________________________________
>
> • This email and any files transmitted with it are CONFIDENTIAL and
> intended
>  solely for the use of the individual or entity to which they are
> addressed.
> • Any unauthorized copying, disclosure, or distribution of the material
> within
>  this email is strictly forbidden.
> • Any views or opinions presented within this e-mail are solely those of
> the
>  author and do not necessarily represent those of Odyssey Financial
> Technologies SA unless otherwise specifically stated.
> • An electronic message is not binding on its sender. Any message referring
> to
>  a binding engagement must be confirmed in writing and duly signed.
> • If you have received this email in error, please notify the sender
> immediately
>  and delete the original.
>

RE: Is it possible to turn off AutoDetach?

Posted by Michael Vorburger <mv...@odyssey-group.com>.
> I tried to turn off auto detaching after commit or entity manager
closing by setting openjpa.AutoDetach property to "false" or to empty
value, but it seems not to work as I expected.

Funny to see this email today.. I coincidentally tried this last week as
well! I got it working on one open EM directly, with this (but read on):

  OpenJPAEntityManager oem = (OpenJPAEntityManager)em;
  System.out.println(oem.getAutoDetach());
  EnumSet<AutoDetachType> d = oem.getAutoDetach();
  d.clear();
  oem.setAutoDetach(d); 

but NOT, whatever I tried, with any config. on the
EntityManagerFactory...

> I know that this behavior is not exactly consistent with JPA standard.

Exactly; so after a good night's sleep we're not using above, and found
another solution to our "problem" instead.

PS, if anybody is interested: The problem why we also initially wanted
to turn off auto detaching for entity manager closing was that the
http://static.springsource.org/spring/docs/2.0.8/api/org/springframework
/orm/jpa/SharedEntityManagerCreator.html "will fall back to a newly
created EntityManager per operation" for a non-transactional read, so it
closes the EM in its Proxy, and thus stuff detaches before you get a
chance to do anything in between.  We are now going to do what we wanted
to do before Spring does its close() and implicit detach in a @PostLoad
instead.


-----Original Message-----
From: Adam Borkowski [mailto:borkos.devel@gmail.com] 
Sent: Monday, November 16, 2009 6:16 PM
To: users@openjpa.apache.org
Subject: Is it possible to turn off AutoDetach?


I tried to turn off auto detaching after commit or entity manager
closing by setting openjpa.AutoDetach property to "false" or to empty
value, but it seems not to work as I expected.

Is there any possibility to turn AutoDetach off?
I'm using OpenJPA 1.2.1 version.

I know that this behavior is not exactly consistent with JPA standard.

Thanks,
Adam Borkowski


--
View this message in context:
http://n2.nabble.com/Is-it-possible-to-turn-off-AutoDetach-tp4013250p401
3250.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

____________________________________________________________

� This email and any files transmitted with it are CONFIDENTIAL and intended
  solely for the use of the individual or entity to which they are addressed.
� Any unauthorized copying, disclosure, or distribution of the material within
  this email is strictly forbidden.
� Any views or opinions presented within this e-mail are solely those of the
  author and do not necessarily represent those of Odyssey Financial
Technologies SA unless otherwise specifically stated.
� An electronic message is not binding on its sender. Any message referring to
  a binding engagement must be confirmed in writing and duly signed.
� If you have received this email in error, please notify the sender immediately
  and delete the original.

Re: Is it possible to turn off AutoDetach?

Posted by Adam Borkowski <bo...@gmail.com>.
> What is the reason that you want to disable AutoDetach?

Rick -

We are preparing to migrate from KODO library to pure OpenJPA 1.2.1 version.
We are aiming for JPA compatibility eventually, but as the first shot I
would like to be as close as possible to previous behavior of OpenJPA (which
was embedded inside KODO).
That's why I would like to turn AutoDetach off.

Michael V. -

Thanks to your comment I realized that handling that from a code level will
be the easiest way to disable AutoDetach (bypassing configuration problem),
as fortunately we are controlling creation of EntityManagers. :)

Thanks,
Adam

-- 
View this message in context: http://n2.nabble.com/Is-it-possible-to-turn-off-AutoDetach-tp4013250p4018402.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Is it possible to turn off AutoDetach?

Posted by Rick Curtis <cu...@gmail.com>.
Adam -

What is the reason that you want to disable AutoDetach?

-- 
Thanks,
Rick

On Mon, Nov 16, 2009 at 11:16 AM, Adam Borkowski <bo...@gmail.com>wrote:

>
> I tried to turn off auto detaching after commit or entity manager closing
> by
> setting
> openjpa.AutoDetach property to "false" or to empty value, but it seems not
> to work as I expected.
>
> Is there any possibility to turn AutoDetach off?
> I'm using OpenJPA 1.2.1 version.
>
> I know that this behavior is not exactly consistent with JPA standard.
>
> Thanks,
> Adam Borkowski
>
>
> --
> View this message in context:
> http://n2.nabble.com/Is-it-possible-to-turn-off-AutoDetach-tp4013250p4013250.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>