java - Speed Up Hibernate Initialization -


i'm having java ee application runs on jboss 7. in order tdd, i'm setting embedded tests use arquillian embedded weld , h2 embedded database.

this works fine, initial startup of hibernate takes considerable amount of time (5-10 seconds) , haven't included jpa entities yet. have tried use persisted oracle db instead avoid table creation, doesn't make of difference.

the main problem seems hibernate goes through entities , validates , prepares crud methods, named queries , on.

is there way tell hibernate lazily when needed (or not @ all)? of time, there subset of entities , queries involved in test case, i'd happily trade in execution time start-up time while implementing.

any ideas?

i know use subset of entities, it's difficult have relations other entities not needed in test context. or there easy way 'deactivate' such relations generate subsets of database?

clarification

it seams it's not clear problem is, i'll try clarify:

  • i have set testing environment arquillian (embedded weld) sets embedded database (h2) jpa enabled testing
  • i use approach test driven development (tdd), means have following workflow on local developing machine:
    1. create test case
    2. run test case
    3. if test case fails, implement necessary changes , go 2.
  • normally, 1 perform steps 2 , 3 couple of times before finishing feature means run single test ide has set entire testing jvm arquillian, weld, embedded db , whatever run single test.

so scenario. i've noticed running single test takes around 10 seconds, not end of world, rather long tdd. , when further investigated, i've noticed of time goes hibernate setting internal structures (it's not weld, arquillian, schema creation or whatever, hibernate getting ready provide entitymanager).

so question is: there way speed hibernate initialization can drop these 10 seconds maybe 1-2 seconds? wouldn't care if it's sort of hack (like keeping testing jvm hibernate alive during multiple manual test runs or deactivating validations or optimizations of hibernate). issue start time single test. consecutive tests run fine , fast, don't have problem full regression testing or testing on build server.

hope makes case bit clearer...

let me guess, using junit library?

database schema creation isn't time-consuming operation (although depends on amount of entities).
personally, if you, run junit tests testng (yes, testng can run junit tests out of box) , take @ <your-module>/test-output/index.html (particularly sections chronological view , times). know operations time-consuming. , such information, can go further.

furthermore, couple of advices:

  1. arquillian tests remote (or managed) containers faster, because start server once.
  2. h2 embedded database isn't bad choice, really. typically don't have abandon (typically, because application may use of target database features, not present in h2).
  3. there arquillian suite extension lets deployment once , reuse across test classes. in case of many tests, extension can speed tests execution significantly.
  4. you can test entities outside container (so called standalone jpa transaction-type="resource_local"). fastest way, suits testing entities annotations, relations, queries , on.

edit

there number of ways task better.
couple of points:

  1. you don't have re-create database every time. embedded databases (h2, hsqldb, derby) have server mode in last longer jvm.
  2. if hibernate initialization bothers you, once across tests (i mean keeping entitymanagerfactory between unit tests).
  3. if want avoid database creation, use h2 in server mode , set hibernate not changes (<property name="hibernate.hbm2ddl.auto" value="none" />)

good luck


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -