Announcement Announcement Module
Collapse
No announcement yet.
Problem with ComboPooledDataSource configuration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with ComboPooledDataSource configuration

    Hello,
    It's my first time I'm using ComboPooledDataSource in hibernate, but there's something wrong with my configurations I think, so that when I call DAO to retrieve all data from database this returns me nothing.

    GenView

    Code:
    @RequestMapping(value="/getHospitals.ajax")
    public @ResponseBody Map<String,? extends Object> loadHospitals(){
    
        HashMap<String, List<Hastaneler>> modelMap = new HashMap<String,List<Hastaneler>>();
    modelMap.put("hastaneler", genBUS.getHospitals());
    
    return modelMap;    
    }
    GenBUS

    Code:
    @Service
    @Transactional(isolation = Isolation.DEFAULT, readOnly = false, propagation = Propagation.REQUIRED)
    public class GenBUS implements IGenBUS {
    
        private Log log = LogFactory.getLog(GenBUS.class);
    
        @Autowired
        private SessionClientData   scd;
    
        @Autowired
        private GenDAO genDAO;
    
        private JdbcTemplate jdbcTemplate;
    
        @Autowired
        private ComboPooledDataSource comboPooledDataSource;
    
        @PostConstruct
        public void dataSource2JdbcTemplate() {
            this.jdbcTemplate = new JdbcTemplate(comboPooledDataSource);
        }
    
        public GenDAO getGenDAO() {
            return genDAO;
        }
    
            @Override
        public List<User> getHospitals() {
            return genDAO.loadAllObject(User.class);
        }
    GenDAO

    Code:
    @Repository
    public class GenDAO extends BaseDAO{
    
        private Log log = LogFactory.getLog(GenDAO.class);
    
    
        @Autowired
        private SessionClientData scd;
    
        @Autowired
        private ComboPooledDataSource comboPooledDataSource;
    
        private JdbcTemplate jdbcTemplate;
    
        @PostConstruct
        public void dataSource2JdbcTemplate() {
            this.jdbcTemplate = new JdbcTemplate(comboPooledDataSource);
        }
    
    
        @Autowired
        public GenDAO(SessionFactory sessionFactory) {
            logger.debug("GenDAO constructor is called !!!!!!!!");
            System.out.println("genDaoooooooooooooooo.....");
            setSessionFactory(sessionFactory);
        }
    BaseDAO

    Code:
    public class BaseDAO extends HibernateDaoSupport {
    
        protected org.hibernate.impl.SessionFactoryImpl baseSessionFactory;
    
            public<T> List<T>  loadAllObject(Class<T> clazz) {
    
            return (List<T>) getHibernateTemplate().loadAll(clazz);
        }
    dao.xml


    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
    
        <tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />
    
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="baseSessionFactory"/>
        </bean>
    
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
            <property name="location" value="classpath:/resources/test.properties"/>
        </bean>
    
        <bean id="comboPooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
            <property name="driverClass" value="${database.driverClass}"/>
            <property name="jdbcUrl" value="${database.url}"/>      
    
            <property name="properties">
                <props>
                    <prop key="user">${database.user}</prop>
                    <prop key="password">${database.password}</prop>
                </props>
            </property>
    
            <!--<property name="user" value="${database.user}"/>
            <property name="password" value="${database.password}"/> -->
    
            <property name="maxPoolSize" value="50"/>
            <property name="initialPoolSize" value="2"/>
            <property name="minPoolSize" value="1"/>
            <property name="maxStatements" value="200"/>
            <property name="maxIdleTime" value="300"/>
            <property name="acquireIncrement"  value="10"/>
            <property name="unreturnedConnectionTimeout" value="90"/>
            <property name="maxConnectionAge" value="120"/>
        </bean>
    
    
    
        <bean id="baseSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource" ref="comboPooledDataSource"/>
        <!--    <property name="entityInterceptor">
                <bean class="generic.logging.AuditTrailInterceptor"/>
            </property> -->
            <property name="packagesToScan">
                <list>
                    <value>model.GenUser</value>
                    <value>model.Hastaneler</value> 
                    <value>model.Hastanelerim</value>
                    <value>model.User</value>
                 </list>
            </property>
            <property name="cacheProvider" ref="ehCacheProvider"/>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop> 
                    <prop key="hibernate.max_fetch_depth">2</prop>
                    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                    <prop key="hibernate.cache.use_query_cache">true</prop>
                    <prop key="hibernate.cache.use_second_level_cache">true</prop>
                    <prop key="hibernate.dialect">${database.dialect}</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.use_sql_comments">true</prop>
                    <prop key="hibernate.format_sql">false</prop>
                    <prop key="hibernate.generate_statistics">true</prop>
                    <prop key="current_session_context_class">thread</prop>
                    <!--<prop key="hibernate.hbm2ddl.auto">none</prop>-->
                </props>
            </property>
            <!--  <property name="eventListeners">
                <map>
                    <entry key="pre-insert"><bean class="generic.logging.HibernateAuditLogListener"/></entry>
                    <entry key="pre-delete"><bean class="generic.logging.HibernateAuditLogListener"/></entry>
                    <entry key="pre-update"><bean class="generic.logging.HibernateAuditLogListener"/></entry>
             </map>
            </property>-->
        </bean>
    
    
         <bean id="ehCacheProvider" class="org.hibernate.cache.EhCacheProvider"/>
    </beans>
    test.properties

    Code:
    database.url=jdbc:mysql://127.0.0.1:3306/acilservis
    database.driverClass=com.mysql.jdbc.Driver
    database.user=root
    database.password=
    database.dialect=org.hibernate.dialect.MySQLDialect
    format_sql=true
    show_sql=true

    And also I'm using Mysql InnoDB as a database engine...Any suggestions?

  • #2
    [Solved]

    I've solved this by changing jdbcTemplate...I reconfigured it to use my sessionFactory, and that worked!

    Comment


    • #3
      Your code is wrong/flawed (and your configuration) on multiple levels.

      1) Don't program to classes but to interfaces
      2) NEVER mess around with the current_session_context_class or hibernate.transaction.factory_class UNLESS you use JTA (which you aren't). Basically your current configuration breaks proper tx support.

      Code:
      public class BaseDAO extends HibernateDaoSupport {
      
          protected org.hibernate.impl.SessionFactoryImpl baseSessionFactory;
      
              public<T> List<T>  loadAllObject(Class<T> clazz) {
      
              return (List<T>) getHibernateTemplate().loadAll(clazz);
          }
      and
      Code:
      @Autowired
          private ComboPooledDataSource comboPooledDataSource;
      are flawed use SessionFactory and DataSource but NOT the concrete implementation, if you switch datasources (or hibernate version) basically your code stops working!!!

      Also in your configuration there is nothing (our you didn't provide) that does anything with @Autowired.

      Comment


      • #4
        Also in your configuration there is nothing (our you didn't provide) that does anything with @Autowired.
        That part was in my applicationContext.xml, I've not put that here as it doesn't have any interaction with db..And I know there was a small mess in my code, I have already fixed them. thanks for your reply.

        Comment

        Working...
        X