Are you working with really large resultsets? What repository are you using? I've encountered similar issues and it came down to database settings for hibernate.
Here are a few other questions to check out:
Simple hibernate query returning very slowly
Hibernate queries slow down drastically after an entity is loaded in the session
For hibernate, I've found the following settings you may tweak to improve performance. :
// update - Create if schema doesn't exists; update if column doesn't
// exist
// create - Empties the database before creating it
// create-drop - Drops the database when the SessionFactory is closed
config.setProperty("hibernate.hbm2ddl.auto", hbm2ddlMode);
config.setProperty("hibernate.cache.use_query_cache", "true");
config.setProperty("hibernate.cache.use_second_level_cache", "true");
config.setProperty("hibernate.cache.region.factory_class",
"org.hibernate.cache.ehcache.EhCacheRegionFactory");
config.setProperty("hibernate.cache.provider_class",
"org.hibernate.cache.EhCacheProvider");
// config.setProperty("hibernate.cache.provider_class",
// "org.hibernate.cache.NoCacheProvider");
config.setProperty("hibernate.jdbc.fetch_size", "1000");
config.setProperty("hibernate.jdbc.batch_size", "50"); //batches network calls in one
config.setProperty("hibernate.jdbc.use_scrollable_resultset", "true");
config.setProperty("hibernate.connection.provider_class",
"org.hibernate.connection.C3P0ConnectionProvider");
config.setProperty("hibernate.c3p0.acquire_increment", "1");
config.setProperty("hibernate.c3p0.idle_test_period", "10");
config.setProperty("hibernate.c3p0.min_size", "1");
config.setProperty("hibernate.c3p0.max_size", "8");
config.setProperty("hibernate.c3p0.timeout", "10");
config.setProperty("javax.persistence.validation.mode", "none");
config
.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
config.setProperty("hibernate.show_sql", "false");
Note, these specific settings may not be ideal for your database, but you should be able to improve performance by tweaking the properties above. Detailed explanation can be found on the doc site.
For sqlite, you have to tweak a few additional settings:
config.setPageSize(4096);
config.setCacheSize(-256);
config.setSharedCache(true);
config.setReadUncommited(true);
//Be careful with these settings if needed for concurrency
//***************************************************
config.setLockingMode(LockingMode.NORMAL);
config.setSynchronous(SynchronousMode.NORMAL);
config.setJournalMode(JournalMode.WAL);
config.setTempStore(TempStore.MEMORY);
//***************************************************
Postgres is a bit simpler and more isolated to the database settings itself. However, keep in mind the query optimizer kicks in after the first query run.