users@glassfish.java.net

Re: Does the wirte operation of EM must be executed in a transaction?

From: <glassfish_at_javadesktop.org>
Date: Tue, 01 Jul 2008 07:08:28 PDT

> Hi,
> I have a question about Entity Manager,
> does the wirte data opertion(such as persiste/remove)
> must
> be executed in a transaction?

Yes.

> In the BMT ejb bean, does the
> EntityManager.persiste() method
> must be a JTA transaction

Yes. Use UserTransaction in BMT session beans.

> or in the {
> em.getTransaction.begin
> ).....em.getTransaction.commit() }?

ONLY IF the entity manager uses resource local transaction, which is very rare in JavaEE environment.

> if not, does the EntityManager.persiste() will not
> wirte to data
> to database?

Exception

> I checked the JPA specification, did not find the
> instruction.
>

It's in the spec, but the JPA spec probably doesn't mention this particular usecase.

-cheng
[Message sent by forum member 'cf126330' (cf126330)]

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