users@glassfish.java.net

Re: Persistence Glassfish RESOURCE_LOCAL

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 27 Jul 2009 14:08:56 -0700

glassfish_at_javadesktop.org wrote:
> Thanks for your help.
>
> But when is RESOURCE_LOCAL needed? When is it helpful I mean. Isn't JTA always the better solution.

It's helpful if you need to access a datasource outside a transaction (e.g. to
log something whether the transaction commits or rolls back), or if you are
using pre-Java EE 5 configuration where your only option to get a hold of emf is
to call Persistence.createEMF().

>
> Also, i wasn't aware of this kind of lookup you are citing: em = ic.lookup(".../mypu");
>
> I'm only aware of the kind of lookup mentioned here: http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html

Sahoo is always right :). I was just sketching the code and he provided all the
details.

Regards,
-marina

>
> PersistenceContext(name="persistence/LogicalName", unitName="ActualPUNameAsItAppearsInPersistence.xml")
> public class RegistrationServlet extends HttpServlet {
> @Resource private UserTransaction utx;
> public void service ( HttpServletRequest req , HttpServletResponse resp)
> throws ServletException, IOException {
> Context envCtx = InitialContext().lookup("java:comp/env");
> EntityManager em = (EntityManager) envCtx.lookup("persistence/LogicalName");
> ...
>
>
> or
>
>
>
> < persistence-context-ref>
> < persistence-context-ref-name>
> persistence/LogicalName
> </persistence-context-ref>
> < persistence-unit-name>
> ActualPUNameAsItAppearsInPersistence.xml
> </persistence-unit-name>
> </persistence-context-ref>
>
>
>
> Is your example different? It might be useful, so i'm asking.
> [Message sent by forum member 'vladbalan' (vladbalan)]
>
> http://forums.java.net/jive/thread.jspa?messageID=357747
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>