I'm using spring data jpa, rest, hibernate entitymanager 4.3.6 with spring boot, and initializing is too slow. More than 1m+.
Hibernate walks through all attributes, and generate query on startup.
How can I prevent this?
Log: Log file on github gist
Bean definition:
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan("com.ceram1.openauth.persistence.model");
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
em.setSharedCacheMode(SharedCacheMode.ALL);
return em;
}
properties config:
p.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
p.setProperty("hibernate.query.startup_check", "false");
p.setProperty("hibernate.show_sql", "true");
p.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
p.setProperty("jadira.usertype.autoRegisterUserTypes", "true");
p.setProperty("hibernate.connection.CharSet", "utf8");
p.setProperty("hibernate.connection.characterEncoding", "utf8");
p.setProperty("hibernate.connection.useUnicode", "true");
p.setProperty("hibernate.cache.use_second_level_cache", "false");
p.setProperty("hibernate.cache.use_query_cache", "false");
You can do that by placing annotation Entity(dynamicInsert=true, dynamicUpdate=true) for each class for which you don't want query to be generated on startup. This is lengthy coding part. But will be helpful if you want that.
Reference: Hibernate Recipe book.
But this has performance issues at runtime here: Why does Hibernate set dynamic insert=false by default
Here is another link: @DynamicInsert @DynamicUpdate does not work?
Sorry, question title was wrong. It was slow because of jadira (hibernate custom type).
Now I noticed that generating query is really fast.. (Hibernate is much faster than me)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With