Wednesday, April 14, 2010

DataBase connection configuration in Spring-Hibernate(applicationContext.xml)

in jdbc.properties  

#for Oracle
#jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc:oracle:thin:@192.168.0.69:1521:jijo
#jdbc.username=jijo
#jdbc.password=jijo
#hibernate.dialect=org.hibernate.dialect.Oracle10gDialect


#for MYSQL
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/jijo
jdbc.username=root
jdbc.password=jijo
hibernate.dialect=org.hibernate.dialect.MySQLDialect

hibernate.c3p0.initialPoolSize=10
hibernate.c3p0.minPoolSize=5
hibernate.c3p0.maxPoolSize=25
hibernate.c3p0.acquireRetryAttempts=10
hibernate.c3p0.acquireIncrement=5
hibernate.c3p0.idleConnectionTestPeriod=3600
hibernate.c3p0.preferredTestQuery=SELECT 1;
hibernate.c3p0.testConnectionOnCheckin=false
hibernate.c3p0.maxConnectionAge=100
hibernate.c3p0.maxIdleTime=120


in applicationContext.xml

 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/> 
<property name="initialPoolSize"><value>${hibernate.c3p0.initialPoolSize}</value></property>
<property name="minPoolSize"><value>${hibernate.c3p0.minPoolSize}</value></property>
<property name="maxPoolSize"><value>${hibernate.c3p0.maxPoolSize}</value></property>
<property name="acquireRetryAttempts"><value>${hibernate.c3p0.acquireRetryAttempts}</value></property>
<property name="acquireIncrement"><value>${hibernate.c3p0.acquireIncrement}</value></property>
<property name="idleConnectionTestPeriod"><value>${hibernate.c3p0.idleConnectionTestPeriod}</value></property>
<property name="maxIdleTime"><value>${hibernate.c3p0.maxIdleTime}</value></property>
<property name="maxConnectionAge"><value>${hibernate.c3p0.maxConnectionAge}</value></property>
<property name="preferredTestQuery"><value>${hibernate.c3p0.preferredTestQuery}</value></property>
<property name="testConnectionOnCheckin"><value>${hibernate.c3p0.testConnectionOnCheckin}</value></property>
</bean>


<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="hibernateProperties">
            <props>

                 <prop key="hibernate.dialect">
                    ${hibernate.dialect}
                </prop>

                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.cglib.use_reflection_optimizer">
                    true
                </prop>
                <prop key="hibernate.cache.provider_class">
                    org.hibernate.cache.HashtableCacheProvider
                </prop>
                <prop key="hibernate.c3p0.acquire_increment">${hibernate.c3p0.acquireIncrement}</prop>
                <prop key="hibernate.c3p0.idle_test_period">${hibernate.c3p0.idleConnectionTestPeriod}</prop>
                <prop key="hibernate.c3p0.timeout">${hibernate.c3p0.maxIdleTime}</prop>
                <prop key="hibernate.c3p0.max_size">${hibernate.c3p0.maxPoolSize}</prop>
                <prop key="hibernate.c3p0.min_size">${hibernate.c3p0.minPoolSize}</prop>
                <prop key="hibernate.show_sql">false</prop>
            </props>
        </property>
    </bean>

No comments: