users@glassfish.java.net

Re: JPA missing hibernate's "delete-orhpan" cascading type

From: <glassfish_at_javadesktop.org>
Date: Mon, 16 Apr 2007 16:35:23 PDT

I suspect there is some confusion with regard to what 'managed' and 'detached' actually means.

I myself may not have a good understanding of this, but I can share from my experience that when using JPA in stand alone mode (ie outside of a container), you still interract with the Entity Manager. And the Entity Manager still spits the dummy if you tell it to do stuff to a detached object.

Detached doesn't mean 'outside the container' it means that you've kept a reference to the object outside the lifetime of the transaction. (Yes, we have transactions outside of the container. If you are not using a framework (such as Spring) that can give you transactions, you need to get a transaction from the Entity Manager by hand).

Also, speaking of 'by hand', the annotations for resource injection won't work outside of a DI framework/container, so you have to do that by hand as well. Just tell the EntityManagerFactory which persistence unit (the little chunk of xml with db connection info in it) you are using, and you are good to go.

Actually, given how easy it is to do the 'by hand' bits, unless your DI is trivial to configure, you probably lose more time fiddling the DI than you gain by using DI.
[Message sent by forum member 'rickcarson' (rickcarson)]

http://forums.java.net/jive/thread.jspa?messageID=212627