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 < [email protected]> 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:[email protected]] > Sent: Monday, November 16, 2009 6:16 PM > To: [email protected] > 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. >
