考虑下面的代码,我尝试了多种方法来设置timeout属性,但是它们似乎都不起作用。在休眠文档中,它声明使用“ hibernate.c3p0.timeout”,但这没有用。
https://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/session-configuration.html
@Bean
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);
return txManager;
}
@Bean
public LocalSessionFactoryBean sessionFactory() throws PropertyVetoException {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(getDataSource());
sessionFactory.setPackagesToScan(new String[] {"com.myproject"});
sessionFactory.setHibernateProperties(additionalProperties());
return sessionFactory;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
properties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
properties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
properties.setProperty("hibernate.jdbc.batch_size", env.getProperty("hibernate.jdbc.batch_size"));
//I've tried each of the following (one at a time obviously) but none of them work
properties.setProperty("hibernate.c3p0.checkout_timeout", "1000");
properties.setProperty("hibernate.c3p0.timeout", "1000");
properties.setProperty("c3p0.checkout_timeout", "1000");
properties.setProperty("c3p0.timeout", "1000");
return properties;
}
在打印下面的代码时,我总是得到“超时:-1”
System.out.println("Timeout: "+sessionFactory.getCurrentSession().getTransaction().getTimeout());