Hi Andreas,

I assume you have more than one persistence context. In this case you have
to add the @PersistenceContext annotation to your onSuccess() method.
Otherwise the system doesn't  know which persistence context it should use.

(The related code is in JpaInternalUtils.getEntityManager() and
in EntityManagerManagerImpl)

Hope that helps.

Felix

2015-03-17 11:16 GMT+01:00 Andreas Ernst <a...@ae-online.de>:

> Hi,
>
> i got a ejb with two entities.
>
> All is working fine, but if i persist the entity, it got this error:
>
> Unable to locate a single EntityManager. You must provide the persistence
> unit name as defined in the persistence.xml using the @PersistenceContext
> annotation.
>
>
>   @Inject
>   @PersistenceContext(unitName = "de.aeits_ERDA-CCIS-EJB_ejb_1.01PU")
>   private EntityManager entityManager;
>
>   @Log
>   @CommitAfter
>   Object onSuccess() {
>     logger.log(Level.INFO, "erfolgreicher Login von {0}", user);
>     try {
>       Users users = entityManager.find(Users.class, user);
>       logger.log(Level.INFO, "User {0}", user);
>       users.setIp(requestGlobal.getHTTPServletRequest().getRemoteAddr());
> //      entityManager.getTransaction().begin();
>       entityManager.merge(users);
> //      entityManager.getTransaction().commit();
>     } catch (Exception e) {
>       logger.log(Level.INFO, "Es ist ein Fehler aufgetreten: {0}", e);
>     }
>     return Index.class;
>   }
>
>
> If i remove the annotation @CommitAfter and do it with
> entityManager.getTransaction().begin() and 
> entityManager.getTransaction().commit(),
> it works.
>
> Any hints?
>
> TIA
> Andreas
> --
> ae | Andreas Ernst | IT Spektrum
> Postfach 5, 65612 Beselich
> Schupbacher Str. 32, 65614 Beselich, Germany
> Tel: +49-6484-91002 Fax: +49-6484-91003
> a...@ae-online.de | www.ae-online.de
> www.tachyon-online.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to