8 Replies Latest reply on Aug 3, 2009 6:01 AM by luxspes

    Web Beans, manual flush and DAO layer

    asookazian

      So I was reading section 16.4.3 Utilizing dependency injection in JPA/Hibernate book and am wondering how this example would relate in a Web Beans context. 


      So there's a SFSB with extended PC and Hibernate manual flush.  There are a couple of DAO classes injected via @EJB.


      Typically DAO classes are implemented as SLSBs, not SFSBs as they are service objects that don't maintain state.


      So what I'm trying to understand is how you would implement/achieve this without Hibernate manual flush enabled other than making the DAOs SFSBs.


      The goal is to achieve atomic conversation and have the PC propagated b/n method calls by mixing a SFSB backing bean or controller and SLSB DAOs.


      And then why is it that JPA 2.0 expert group won't accept adding manual flush mode when you think about this problem?  How do they recommend us to solve this currently w/o manual flush if we want to keep our DAOs implemented as SLSBs and achieve atomic conversations?

        • 1. Re: Web Beans, manual flush and DAO layer
          baz


          Also i have not asked before i am interested in this topic too:



          And then why is it that JPA 2.0 expert group won't accept adding manual flush mode when you think about this problem? How do they recommend us to solve this currently w/o manual flush if we want to keep our DAOs implemented as SLSBs and achieve atomic conversations?

          • 2. Re: Web Beans, manual flush and DAO layer
            pmuir

            Carsten Höhne wrote on Jul 26, 2009 17:46:




            Also i have not asked before i am interested in this topic too:

            And then why is it that JPA 2.0 expert group won't accept adding manual flush mode when you think about this problem? How do they recommend us to solve this currently w/o manual flush if we want to keep our DAOs implemented as SLSBs and achieve atomic conversations?




            That's not really a topic we can answer here. I suggest you contact the expert group.

            • 3. Re: Web Beans, manual flush and DAO layer
              pmuir

              Arbi Sookazian wrote on Jul 25, 2009 08:13:


              So there's a SFSB with extended PC and Hibernate manual flush.  There are a couple of DAO classes injected via @EJB.

              Typically DAO classes are implemented as SLSBs, not SFSBs as they are service objects that don't maintain state.

              So what I'm trying to understand is how you would implement/achieve this without Hibernate manual flush enabled other than making the DAOs SFSBs.


              Why do you not want Hibernate's manual flush mode enabled?


              The goal is to achieve atomic conversation and have the PC propagated b/n method calls by mixing a SFSB backing bean or controller and SLSB DAOs.


              In that case:


              class PersistenceContextManagerManager {
              
                 @Produces @Database @PersistenceContext @ManualFlushMode @ConversationScoped
                 EntityManager entityManager;
              
                 @Produces @Database @PersistenceUnit @ManualFlushMode @ConversationScoped
                 EntityManagerFactory entityManagerFactory;
              
              }



              where @Database is a binding type you define, and @ManualFlushMode could be a decorator provided as part of Seam 3 that looks a bit like:


              @Decorator
              class ManualFlushModeEntityManager implements EntityManager {
              
                 @Delegate @Any EntityManager entityManager;
              
                 private void enableManualFlushMode() {
                    if (entityManager.getDelegate() instanceof Session)
                       ((Session) entityManager.getDelegate()).setFlushMode(FlushMode.MANUAL);
                 }
              
                 public void persist(Object entity) {
                    enableManualFlushMode();
                    entityManager.persist(entity);
                 }
              
                 // And so on
              }

              • 4. Re: Web Beans, manual flush and DAO layer

                Arbi Sookazian wrote on Jul 25, 2009 08:13:



                And then why is it that JPA 2.0 expert group won't accept adding manual flush mode when you think about this problem?  How do they recommend us to solve this currently w/o manual flush if we want to keep our DAOs implemented as SLSBs and achieve atomic conversations?



                Remember this thread, it seems that (other than the Hibernate developers) the other members see no point for adding Api sugar to make it easier:




                James Sutherland wrote:

                Not sure I understand but you seem to want to ignore the container JPA transactions correct?


                Normally when using EJB any work you do inside a JTA transaction will be committed when that JTA transaction commits, normally at the end of the SessionBean method, or when the JTA transaction is committed explicitly. You seem to want your EntityManager transaction to span multiple server calls, and multiple JTA transactions. For this I think you would want to use an application managed EntityManager. Either do not use JTA at all, just use EntityManager transactions and commit whenever you desire, or use joinTransaction() when you wish to commit to commit along with the active JTA transaction.


                It might be harder to do it, but if it can be done, I guess the expert group believes it is better to deal with things that can not be done first, and then make it easier to do things that are already possible

                • 5. Re: Web Beans, manual flush and DAO layer
                  • 6. Re: Web Beans, manual flush and DAO layer
                    asookazian

                    Pete Muir wrote on Jul 28, 2009 20:13:



                    Arbi Sookazian wrote on Jul 25, 2009 08:13:


                    So there's a SFSB with extended PC and Hibernate manual flush.  There are a couple of DAO classes injected via @EJB.

                    Typically DAO classes are implemented as SLSBs, not SFSBs as they are service objects that don't maintain state.

                    So what I'm trying to understand is how you would implement/achieve this without Hibernate manual flush enabled other than making the DAOs SFSBs.


                    Why do you not want Hibernate's manual flush mode enabled?




                    My intention is not disabling or avoiding Hibernate manual flush mode.  I am an advocate of it.  The reason I asked this is I was wondering what the EE group recommends or how to handle it without manual flush...

                    • 7. Re: Web Beans, manual flush and DAO layer

                      Arbi Sookazian wrote on Jul 31, 2009 22:33:



                      My intention is not disabling or avoiding Hibernate manual flush mode.  I am an advocate of it.  The reason I asked this is I was wondering what the EE group recommends or how to handle it without manual flush...



                      I do not think that your intention is disabling  manual flush  (and that is also not my intention). My intention is to understand why Hibernate authors think it is such a great Hibernate feature, and the other members of the expert group seem to think it is not something that is actually needed.

                      • 8. Re: Web Beans, manual flush and DAO layer

                        Ha ha ha, I guess your intention and my intention are the same... ;-)