2 Replies Latest reply on Jan 29, 2008 3:43 AM by d00roth

    transaction failed" using injected JavaBean

      Hi all,

      I have struggled some time with a problem I get when trying to persist some objects. I use the exact same setup as jboss-seam-jpa running om tomcat6 without jboss embedded. (JavaBean an POJO:s).

      Persisting an object with

      @Name("register")
      public class RegisterAction {
       @In
       private EntityManager em;
      
       public void register() {
       em.persist(someObject);
       }
      }
      


      works perfectly, even without the @Transactional annotation. However this:

      @Name("register")
      public class RegisterAction {
       @In
       private MyService service;
      
       public void register() {
       service.register(someObject);
       }
      }
      
      @Name("service")
      @AutoCreate
      public class MyService {
       @In
       private EntityManager em;
      
       public void register(Object someObject) {
       em.persist(someObject);
       }
      }
      


      does not work(and I have tried using @Transactional on 'register' and MyService). I get a "Transaction failed" in my jsf h:messages, but apart from that, there is no error message what so ever.

      I guess I have missed something fundamental, especially when I read this in the Seam doc:

      25.3... Seam JavaBean components do not provide declarative transaction demarcation like session beans do. You could manage your transactions manually using the JTA UserTransaction or declaratively using Seam's @Transactional annotation. But most applications will just use Seam managed transactions when using Hibernate with JavaBeans.


      1.2.1.2... Our session bean action listener performs the business and persistence logic for our mini-application. In more complex applications, we might need to layer the code and refactor persistence logic into a dedicated data access component. That's perfectly trivial to do. But notice that Seam does not force you into any particular strategy for application layering.


        • 1. Re: transaction failed

          Hi,

          I have the same problem. Did you resolve it?

          Regards

          Jarek

          • 2. Re: transaction failed

            Unfortunately not. I have no idea why.

            I 'solved' this issue by having transactional spring dao classes do _everything_ for me, i.e. something like:

            myDao.addLogToJob(LogItem log, Job job) {
            job = em.find(job.getId());
            job.getLogs().add(log);
            em.merge(job);
            }

            Ugly and bad in every way possible, but at least it worked and was ready to deadline... :-)