设置自动冲洗弹簧JPA

时间:2014-02-04 09:59:25

标签: java spring hibernate jpa spring-data

您好我使用以下配置:

@Configuration
@EnableJpaRepositories
public class SpringContextConfiguration {


    @Bean
    public TestsSetup testSetup(){
        return new TestsSetup();
    }

    @Bean
    public TransactionAwareDataSourceProxy dataSource(){
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
        ds.setUrl("jdbc:oracle:thin:@AAAA");
        ds.setUsername("AAA");
        ds.setPassword("AAA");
        ds.setDefaultAutoCommit(true);
        TransactionAwareDataSourceProxy tp = new TransactionAwareDataSourceProxy();
        tp.setTargetDataSource(ds);
        return tp;
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
        LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
        lef.setDataSource(dataSource);
        lef.setJpaVendorAdapter(jpaVendorAdapter);
        lef.setPackagesToScan("setup");
        return lef;
    }

    @Bean
    public JpaVendorAdapter jpaVendorAdapter() {
        HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
        hibernateJpaVendorAdapter.setShowSql(true);
        hibernateJpaVendorAdapter.setGenerateDdl(false);
        hibernateJpaVendorAdapter.setDatabase(Database.ORACLE);
        return hibernateJpaVendorAdapter;
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        return new JpaTransactionManager();
    }
}
2221 [main] DEBUG org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
2221 [main] DEBUG org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
2221 [main] DEBUG org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
2221 [main] DEBUG org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
2221 [main] DEBUG org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
2222 [main] DEBUG org.hibernate.cfg.SettingsFactory - Wrap result sets: disabled

如何启用自动刷新功能。 感谢

2 个答案:

答案 0 :(得分:1)

您要查找的媒体资源是hibernate.transaction.flush_before_completion

答案 1 :(得分:-1)

将hibernate的autocommit属性设置为true,如下所示

<property name="hibernate.connection.autocommit">true</property> 

详细了解配置设置

<强> Hibernate Configuration

<强> 3.4. Optional configuration properties

希望这能解决您的问题!