4 Replies Latest reply on Jul 1, 2009 8:42 PM by Diego Y K

    Seam not releasing connections from the pool

    Diego Y K Newbie

      Hi I'm using Seam Managed Persistence in my application.


      I have a page with 2 select boxes that are populates trough a method call from a Sem Managed SFSB.


      This two methods have only this signature


      entityManager.createQuery("select o from Usuario o").getResultList();



      I can't find the source of my problem but after some use of the SFSB my connections from the pool ends all used up.


      This is my SFSB source code.




      @Stateful
      @Name("connectorAction")
      @Local(ConnectorActionInterface.class)
      @Remote(ConnectorActionInterface.class)
      @Scope(ScopeType.CONVERSATION)
      public class ConnectorAction implements ConnectorActionInterface {
           
           /**
            * EntityManager
            */
           @In
           protected EntityManager entityManager;
           
           /**
            * Connector properties
            */
           @In @Out
           protected Connector connector;
           
           /**
            * Selected connector
            */
           private Integer selectedConnectorId;
           
           /**
            * List of connectors
            */
           @DataModel
           protected List<Connector> connectorList;
           
           /**
            * Factory for Connector type
            * @return list of connector type
            */
           @Factory("connectorTypeList")
           @SuppressWarnings(value = "unchecked")
           @End
           public List<ConnectorType> typeListFactory() {
                return entityManager.createQuery("select o from ConnectorType o").getResultList();     
           }
           
           /**
            * Factory for Connector Direction 
            * @return list of connector direction
            */
           @Factory("connectorDirectionList")
           @SuppressWarnings(value = "unchecked")
           @End
           public List<ConnectorDirection> directionListFactory() {
                return entityManager.createQuery("select o from ConnectorDirection o").getResultList();
           }
           
           /**
            * Insert a connector
            * 
            * @return connector search
            */
           @Override
           public String insert() {
                return "ok";
           }
      
           /**
            * Searches a connector
            * 
            * @return connector search
            */
           @SuppressWarnings("unchecked")
           //@Factory("connectorList")
           @Override
           public List<Connector> search() {
                HibernateSessionProxy session = ((HibernateSessionProxy) entityManager.getDelegate());
                
                Example example = Example.create(connector).excludeZeroes() // exclude zero valued properties
                     .ignoreCase() // perform case insensitive string comparisons
                     .enableLike(MatchMode.ANYWHERE); // match string anywhere on the fields
                
                connectorList = session.createCriteria(Connector.class).add(example).list();
                
                
                return connectorList;
           }
           
           /**
            * Select a connector
            * 
            * @param selectedConnector selected connector
            * @return String jsf control
            */
           @Override
           @Begin(join = true)
           public String selectConnector(Connector selectedConnector) {
                selectedConnectorId = selectedConnector.getId();
                connector = selectedConnector;
                return "goNewConnector";
           }
           
           /**
            * Creates a connector
            * 
            * @return String jsf control
            */
           @Override
           @End
           public String create() {
                connector.setServiceInterfaceType(
                          (ServiceInterfaceType) entityManager.find(ServiceInterfaceType.class, 1));
                entityManager.persist(connector);
                
                
                return "created";
           }
           
           /**
            * Removes a connector
            * 
            * @return String jsf control
            */
           @Override
           @End
           public String remove() {
                connector = entityManager.find(Connector.class, selectedConnectorId);
                
                entityManager.remove(connector);
                
                return "created";
           }
           
           
           /**
            * Removing instances
            */
           @Remove
           @Override
           @End
           public void destroy() {
                connector = null;
                connectorList = null;
           }
      
      
      }



        • 1. Re: Seam not releasing connections from the pool
          Francisco Jose Peredo Noguez Master

          What application server are you using?
          What is your JNDI Datasource configuration?
          What is in your persistence.xml?

          • 2. Re: Seam not releasing connections from the pool
            Shervin Asgari Master

            Why are u ending the conversation so many times? That is perhap why you run out of pool. My guess at least.
            Only end when u need to end.


            Also why are u using both @Remote and @Local?
            Is that necessary?

            • 3. Re: Seam not releasing connections from the pool
              Diego Y K Newbie

              I only ended the conversation so many times because I thought that my problems with the connection pool was the lack of end conversations. But the error persists, with or without the @End annotation on my methods.


              I'm running Seam 2.1 on Glassifsh 2.1.


              This is my sun-resources.xml




              <jdbc-connection-pool allow-non-component-callers="false"
                        associate-with-thread="false" connection-creation-retry-attempts="0"
                        connection-creation-retry-interval-in-seconds="10"
                        connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0"
                        connection-validation-method="auto-commit"
                        datasource-classname="net.sourceforge.jtds.jdbcx.JtdsDataSource"
                        fail-all-connections="false" idle-timeout-in-seconds="600"
                        is-connection-validation-required="true"
                        is-isolation-level-guaranteed="true" lazy-connection-association="true"
                        lazy-connection-enlistment="true" match-connections="false"
                        max-connection-usage-count="0" max-pool-size="20"
                        max-wait-time-in-millis="60000" name="configToolPool"
                        non-transactional-connections="false" pool-resize-quantity="5"
                        res-type="javax.sql.DataSource" statement-timeout-in-seconds="10000"
                        steady-pool-size="10" validate-atmost-once-period-in-seconds="0"
                        wrap-jdbc-objects="false">



              persistence.xml




              <persistence-unit name="configToolPool" transaction-type="JTA">
                        <provider>org.hibernate.ejb.HibernatePersistence</provider>
                        <jta-data-source>jdbc/configToolPool</jta-data-source>
                       <properties>
                           <property name="hibernate.show_sql" value="false" />
                           <property name="hibernate.format_sql" value="false" />
                           <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
                           <property name="hibernate.connection.isolation" value="4096"/>
                           <property name="hibernate.query.startup_check" value="false" />
                           <property name="hibernate.default_batch_fetch_size" value="30" />
                           <property name="hibernate.transaction.manager_lookup_class"
                                  value="org.hibernate.transaction.SunONETransactionManagerLookup" />
                           
              
                              <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" />
                                <property name="net.sf.ehcache.configurationResourceName" value="META-INF/ehCache.xml" />              
                             <property name="hibernate.cache.use_query_cache" value="true" />
                             <property name="hibernate.cache.use_minimal_puts" value="false" />
                             <property name="hibernate.cache.use_second_level_cache" value="true" />
                        </properties>     
                   </persistence-unit>



              components.xml


              <core:init jndi-pattern="java:comp/env/ConfigTool/#{ejbName}/local"
                        debug="true" />
              
                   <transaction:ejb-transaction />
                   
                   <core:manager conversation-timeout="120000" 
                                concurrent-request-timeout="500"
                                conversation-id-parameter="cid"/>  
              
                   <persistence:entity-manager-factory
                        name="entityManagerFactory" persistence-unit-name="configToolPool" />
              
                   <persistence:managed-persistence-context
                        name="entityManager" auto-create="true" entity-manager-factory="#{entityManagerFactory}"/> 



              • 4. Re: Seam not releasing connections from the pool
                Diego Y K Newbie

                I've fixed my problem changing the definition of my connection pool sun-resources-ejb.xml




                non-transactional-connections="false"