How to get jdbc.batch_size property value at runtime for a web application using Spring MVC and Hibernate?

According to what I have found so far, I can use the following code:

    LocalSessionFactoryBean sessionFactory = (LocalSessionFactoryBean) super.getApplicationContext (). GetBean ("& sessionFactory");
    System.out.println (sessionFactory.getConfiguration (). BuildSettings (). GetJdbcBatchSize ());

but then I get a Hibernate exception:

org.hibernate.HibernateException: local data source not found for configuration - dataSource property must be set to LocalSessionFactoryBean

Can someone shed some light?

+3
source share
2 answers

( , Spring):

System.out.println(sessionFactory.getConfiguration().getProperty("hibernate.jdbc.batch_size"))
+3

Hibernate, , getConfiguration SessionFactory. SessionFactory , , . :

((SessionFactoryImplementor)sessionFactory).getSettings().getJdbcBatchSize()

, , , . , , try try/catch Throwable, , , . Hibernate, , .

+3

Source: https://habr.com/ru/post/1697240/


All Articles