users@glassfish.java.net

Re: JPA - entityManager.flush()

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Thu, 17 May 2007 00:19:13 +0200

2007/5/17, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org>:
> But from my understanding, the container start/ends the transaction at the start/end of the method,
>
> Is there any way to start/end transactions manually?
> I tried, but I get an exception that user transactions are not allowed in container managed beans,
> Is it possible somehow?

Write each transaction in separate, public method in your bean. Use
annotations to declare, that each method requires new transaction.
Create local interface for that bean (if you do not have one already)
and declare those methods in that interface.
Inject SessionContext into your session bean like this:
@Resource SessionContext ctx;
Now, if you want to call one method from within another, use:
ctx.getBusinessObject(BeanInterfaceName.class).methodName(parameters);

-josh

> [Message sent by forum member 'trouby' (trouby)]
>
> http://forums.java.net/jive/thread.jspa?messageID=217502
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>