I am having problems with hibernation because it strikes the database too much. I am exploring some extraction strategies. I want to write some functional unit tests, as my application develops, I can see how many SQL expressions are being called.
I want to know if I can count how many SQL statements are being called. Currently, I set show-sql to true, and then count the SQL queries in the console. I want to do this in code, if possible. Is it possible to calculate how much hibernate SQL hits DB with code?
thanks
EDIT
After @Aleksander Blomskøld answers ....
My test case
StatisticsService statisticsService = new StatisticsService(); Session session = entityManager.unwrap(Session.class); statisticsService.setSessionFactory(session.getSessionFactory()); statisticsService.setStatisticsEnabled(true); List<MyType> r= entityManager.createQuery("from MyType", MyType.class).getResultList(); System.out.println(statisticsService.getQueryExecutionCount()); System.out.println(statisticsService.getQueries()[0]);
The request execution score is set to 1, and if I look at the request, it says that it is "from MyType"
However, in the sql statements that are in the log, I see that there are SQL queries to retrieve MyType and many related classes. Therefore, in fact, I want to know all the SQL that gets into the database due to a call from MyType.
Is that what I need more clearly? Or am I just abusing StatisticService
thanks
source share