从Java应用程序将数据块保存到DB中

时间:2019-01-22 15:48:12

标签: java spring hibernate

我有一个Java批处理程序,该程序是从BPEL流程触发的,该流程用于将记录集插入到数据库中。

记录的大小可能有所不同,但平均约为20,000至40,000。

我的自定义Java批处理从从第三方应用上传到服务器位置的excel中提取数据。

为了执行DML操作,我使用了Hibernate / Spring JDBC框架。

请参考以下我的spring配置文件:

<context:component-scan base-package="mybasepackage" />

<bean id="myProps"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath*:myDB.properties</value>
        </list>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${DB_DRIVER}" />
    <property name="url" value="${DB_URL}" />
    <property name="username" value="${DB_USER}" />
    <property name="password" value="${DB_PASSWORD}" />
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="mypackage" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle12cDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.jdbc.batch_size">20</prop>
            <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.max_size">10</prop>
            <prop key="hibernate.c3p0.max_size">7000</prop>
        </props>
    </property>
</bean>

<bean id="myBatchDao"
    class="mypackage.MyBatchDaoImpl">
    <property name="jdbcTemplate" ref="jdbcTemplate" />
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="myBatchService"
    class="mypackage.MyBatchServiceImpl">
    <property name="myBatchDao" ref="myBatchDao" />
</bean>

<bean id="transactionManager"
    class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

   <tx:annotation-driven transaction-manager="transactionManager" />

我已经在将c3p0用于ConnectionPooling,并且还访问了以下链接:

link1 link2

但仍然出现以下异常:

<org.hibernate.engine.jdbc.spi.SqlExceptionHelper> <BEA-000000> <IO Error: Got minus one from a read call, connect lapse 6370 ms., Authentication lapse 0 ms.>
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction;nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
at org.springframework.orm.hibernate5.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:564)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335) 

0 个答案:

没有答案