3 Replies Latest reply on Apr 22, 2008 5:32 PM by Andy Gibson

    EntityHome with session beans

    Alexander Mashtakov Newbie

      Hi,


      After reading seam reference I decided to experiment
      with EntityHome with session beans and this raised
      several questions:



      1. I created SFSB by extending EntityHome and noticed
         that methods of EntityHome are annotated with
         @Transactional attribute. However, seam reference
         notices do not use such annotation with EJB. But
         my example works as expected. Is it a correct
         usage of EntityHome and SFSB ?


      2. Seam reference says: The Seam Application Framework
         only works with Seam-managed PC
      . Is it possible
         to use EntityManager injected by ebj container ?
         I overrided getEntityManager() and everything works,
         but I'm not sure if it is a correct usage and will not
         cause some side effects.


      3. I noticed that after form submit, all changes are
         saved to database even without explicit call to
         update() method. This is caused by @Transactional
         attribute in getInstance() method, which force
         flush on commit. So,  I did the following in my SFSB:


      
                  @Override
      
                  @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
      
                  public User getInstance() {
      
                              return super.getInstance();
      
                  }
      
      


          and everythig works as expected. Is it possible
          to mix seam's @Transaction and ejb @TransactionAttribute
          annotations together ? Which of them takes the
          precedence ?


      ---
      Regards,
      /Alexander



         

        • 1. Re: EntityHome with session beans
          Andy Gibson Novice

          EntityHome is written to be used as a JavaBean* which is why it has the @transactional annotations. I believe these will be ignored if your bean is an EJB as transaction management will be deferred to the EJB container.


          Everything being saved to the database is because the EJB persistence context lacks the ability to set the flush mode to manual unlike the Seam PC.


          Is there any particular reason not to use the Seam PC? It really does save a lot of trouble and give you a lot of features (just look s:convertEntity for one). If you use the Seam PC this takes away a lot of the headaches and gives you the flush=manual capabilities also


          Cheers,


          Andy



          * I say this because to use EntityHome as an EJB means you have to subclass it and write your own local interface. Under EJB 3.1 though this should be resolved since interfaces are not required?

          • 2. Re: EntityHome with session beans
            Alexander Mashtakov Newbie

            Thank you Andy for explanation. Agree - seems that
            EntityHome is more suitable for POJOs, so I decided
            to avoid it with EJBs for consistency reason. I'm curious
            why ejb spec doesn't include one obviuos thing -

            flush=manual


            which eliminates such side effect. So, and here I switched to
            SMPC.


            Just one question, may be not related to the subject - Is it a
            common approach to use

            TransactionAttributeType.NOT_SUPPORTED


            for ejb methods, that do not perform updates, but only queries ?
            Running query without transaction should be faster, and even in case if exception is raised during query execution - the
            outer transaction (if any) will be rolled back.
            But I'm in doubt - for example s:convertEntity,
            EntytyHome.getInstance() both require active transaction for
            some reason. Why ?


            Thank you,
            /Alexander


            • 3. Re: EntityHome with session beans
              Andy Gibson Novice

              I'm curious why ejb spec doesn't include one obvious thing -


              The whole flushMode=manual is apparently fairly controversial. You will see a number of places where people (Gavin, Pete, the authors of the EJB 3.0 book I was reading this week oddly enough) all lament the fact that the idea of flush=manual was rejected. Take a look at section 8.3.3 of the Seam manual for Gavin's take :



              As the result of a truly stupid and shortsighted decision by certain non-JBoss, non-Sun and non-Sybase
              members of the EJB 3.0 expert group, there is currently no simple, usable and portable way to implement atomic
              conversations using EJB 3.0 persistence.

              As for transactions on query only methods, it is my understanding that all queries run in a transaction, either an implicit one, or explicit.