users@glassfish.java.net

Re: Transaction exception, but I think it should work

From: Ronaldo Rigoni ... <rrigoni_at_gmail.com>
Date: Mon, 21 Sep 2009 08:08:39 -0400

Persist all Person with one transaction in the method addAll();

Ronaldo.

2009/9/21 <glassfish_at_javadesktop.org>

> Hi, this is a little code first:
>
> [code]
> @Local(PersonEAO.class)
> @Stateless(name = "ejb/personEAO")
> public class PersonEAOBean implements PersonEAO {
>
> @PersistenceContext(name = "Test-JPA")
> private EntityManager em;
>
> @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
> @Override
> public void add(Person person) {
> em.persist(person);
> }
>
> @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
> @Override
> public void addAll(List<Person> people) {
> for (Person person : people) {
> add(person);
> }
> }
> }
> [/code]
> The addAll method suspends a possible transaction, and is invoked without
> any transaction. It in turn calls add, which always creates a new
> transaction, in a loop. Add uses an EntityManager to persist, and the call
> fails with a TransactionRequiredException. Why is that, shouldn't the add
> method start and finish the transaction for every call?
> (I do want to call the persist method in a new transaction every time, this
> is a very specific part of the app and this cannot change.)
>
> Regards.
> [Message sent by forum member 'szczyp' (szczyp_at_gmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=364901
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>


-- 
[]'s,
Ronaldo Rigoni
http://www.ronaldorigoni.com.br
Desenvolvedor JEE
Ministério da Educação -  CESPE