Announcement Announcement Module
Collapse
No announcement yet.
Configure C3P0NativeJdbcExtractor, LocalContainerEntityManagerFactoryB En Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configure C3P0NativeJdbcExtractor, LocalContainerEntityManagerFactoryB En

    Hello,

    I am using C3P0 connection pooling in my app. I also use "org.springframework.orm.jpa.LocalContainerEntityM anagerFactoryBean".

    Code:
    <bean id="entityManagerFactory" 
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    		<property name="persistenceUnitManager" ref="persistenceUnitManager" />
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="showSql" value="false" />
    				<property name="generateDdl" value="false" />
    				<property name="database" value="ORACLE"/>				
    				<property name="databasePlatform" value="com.xxx.hibernate.OracleSpatialDialect" />
    			</bean>
    		</property>
    		<property name="persistenceUnitName" value="persistenceUnitTest" />
    </bean>
    Code:
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    	    <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
    		<property name="jdbcUrl" value="${dc.url}" />
    		<property name="user" value="${dc.user}" />
    		<property name="password" value="${dc.password}" />
    		<!--  C3P0 connection pool configuration -->
    	    <property name="minPoolSize" value="5"/>
    		<property name="maxPoolSize" value="20"/>
    		<property name="checkoutTimeout" value="300"/>
    		<property name="maxStatements" value="50"/>
    		<property name="maxIdleTime" value="300"/> 		
    	</bean>
    However, it will NOT work for the statement below.

    Code:
    OracleConnection oc = (OracleConnection) preparedStatement.getConnection();
    So, I went through Spring documentation 3.x, it suggests that it can be done by using C3P0NativeJdbcExtractor.
    I did some research on how to configure it in spring applicationContext.xml, however, I couldn't find anything using entityManagerFactory.
    I am not quite sure where to use the following:

    Code:
    <bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"/>
     
            <!-- LobHandler for Oracle JDBC drivers -->
            <!-- (refers to the NativeJdbcExtractor above to get access to native OracleConnections) -->
            <bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
                    <property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
            </bean>
     
            <!-- NativeJdbcExtractor for the C3P0 connection pool above -->
            <!-- (just needed for oracleLobHandler) -->
            <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor"
                            lazy-init="true"/>
    Please advice.

    Thank you.
    Last edited by xiaofong; Sep 21st, 2010, 03:52 PM.
Working...
X