3

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");
Kai
  • 38,985
  • 14
  • 88
  • 103
ceram1
  • 515
  • 1
  • 6
  • 19
  • It's not a bug, it's a feature. So you can be sure not to be unpleasantly suprised, when a query cannot be generated on runtime; and it saves time **after** the server has come up... – Uwe Allner Oct 08 '14 at 11:10
  • 1
    I know, but I want to disable it for faster development and testing. – ceram1 Oct 08 '14 at 11:12

2 Answers2

1

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?

Community
  • 1
  • 1
Sushant Tambare
  • 526
  • 2
  • 9
  • Thanks for useful informations, but I can't apply it to my project. It does not working even I'm using 4.3.6.Final – ceram1 Oct 08 '14 at 11:52
1

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)

ceram1
  • 515
  • 1
  • 6
  • 19