javahibernatepersistence.xml

How to declare connection properties with ComboPooledDataSource or BasicDataSource


How to declare useFetchSizeWithLongColumn=true with Hibernate? either under com.mchange.v2.c3p0.ComboPooledDataSource or org.apache.commons.dbcp.BasicDataSource in a properties bean configuration file?

I already tried:

<bean id="oracle_prop" lazy-init="false"
      class="org.springframework.util.StringUtils"
      factory-method="collectionToDelimitedString">
    <constructor-arg index="0">
        <list>
            <value>oracle.jdbc.useFetchSizeWithLongColumn=true</value>
        </list>
    </constructor-arg>
    <constructor-arg value=";" index="1" type="java.lang.String"/>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${database.driver}"/>
    <property name="url" value="${database.url}"/>
    <property name="username" value="${database.username}"/>
    <property name="password" value="${database.password}"/>
    <property name="initialSize" value="100"/>
    <property name="maxIdle" value="100"/>
    <property name="maxActive" value="1000"/>
    <property name="connectionProperties" ref="oracle_prop"/>
</bean>

and

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="properties" ref="dataSourceProperties"></property>
    <property name="driverClass" value="${database.driver}"/>
    <property name="jdbcUrl" value="${database.url}"/>
    <property name="user" value="${database.username}"/>
    <property name="password" value="${database.password}"/>
    <property name="initialPoolSize" value="100"/>
    <property name="minPoolSize" value="100"/>
    <property name="maxPoolSize" value="1000"/>
    <property name="maxIdleTime" value="1800"/> 
    <property name="maxStatements" value="50"/> 
</bean>

<bean id="dataSourceProperties" class="java.util.Properties">
    <constructor-arg>
        <props>
            <prop key="oracle.jdbc.useFetchSizeWithLongColumn">true</prop>
        </props>
    </constructor-arg>
</bean>

and

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${database.driver}"/>
    <property name="jdbcUrl" value="${database.url}"/>
    <property name="properties">
        <props>
            <prop key="user">${database.username}</prop>
            <prop key="password">${database.password}</prop>     
            <prop key="useFetchSizeWithLongColumn">true</prop>                  
        </props>
    </property>
    <property name="initialPoolSize" value="100"/>
    <property name="minPoolSize" value="100"/>
    <property name="maxPoolSize" value="1000"/>
    <property name="maxIdleTime" value="1800"/> 
    <property name="maxStatements" value="50"/> 
</bean>

Solution

  • Workaround

    Look for all the long data types and change each manually.

    Select * from user_tab_columns c where c.DATA_TYPE = 'LONG';
    

    Sad to say useFetchSizeWithLongColumn will not work everytime. So if you want to use this property, make sure that the LONG columns you are retrieving are not too big or you may run out of memory.

    For JPA Hibernate, you could also add @Lob Annotation.