2 Replies Latest reply on Nov 13, 2009 4:49 PM by navansys

    PersistenceProvider @PostConstruct bug

    navansys

      The PersistenceProvider class (package org.jboss.seam.persistence) has a method marked @PostConstruct:


         @PostConstruct
         // @Create method not called on stateless components
         public void init()
         {
         }
      



      The @PostConstruct annotation is the wrong class:




      org.jboss.seam.annotations.intercept.PostConstruct





      It should be:




      javax.annotation.PostConstruct




      The Seam Component class, when constructing any component, looks for javax.annotation.PostConstruct annotation and will only execute methods with this annotation on post construct. The persistenceProvider component thus does not get its post construct method invoked. This is especially a problem in HibernatePersistenceProvider which extends PersistenceProvider and overrides the init() method.



         @Override
         public void init()
         {
            super.init();
            featureSet.add(Feature.WILDCARD_AS_COUNT_QUERY_SUBJECT);
         }
      




      As a result, MySQL databases have problems with the Seam library since they require wildcard counts in place of multi-column counts (e.g. select count(a,b) from c does not work in MySQL).


      BTW are there docs for which annotation classes to use? It seems a bit of a dog's breakfast. e.g. @Create annotation comes from another package:


      org.jboss.seam.annotations.



        • 1. Re: PersistenceProvider @PostConstruct bug
          navansys

          I'm going to raise this as a bug when I get a minute. Also, here's my workaround:



          package org.open18.persistence;
          
          import javax.annotation.PostConstruct;
          
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Install;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Scope;
          import org.jboss.seam.annotations.intercept.BypassInterceptors;
          import org.jboss.seam.log.Log;
          import org.jboss.seam.log.Logging;
          import org.jboss.seam.persistence.HibernatePersistenceProvider;
          
          /**
           * Addresses problem with HibernatePersistenceProvider by explicitly
           * calling HibernatePersistenceProvider.init() from
           * a PostConstruct method that actually gets called on postconstruct.
           * 
           */
          @Name("org.jboss.seam.persistence.persistenceProvider")
          @Scope(ScopeType.STATELESS)
          @BypassInterceptors
          @Install(classDependencies={"org.hibernate.Session", "javax.persistence.EntityManager"})
          public class MoBetterHibernatePersistenceProvider extends HibernatePersistenceProvider {
          
              private static Log log = Logging.getLog(MoBetterHibernatePersistenceProvider.class);
          
              @PostConstruct
              public void init()
              {
                 log.debug("MoBetterPersistenceProvider init");
                 super.init();
              }
          
          }
          



          • 2. Re: PersistenceProvider @PostConstruct bug
            navansys

            Looks like this bug has recently been raised in JIRA: JBSEAM-4454