• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate, Spring and H2

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off if this is the wrong place... sorry. I didnt think it really fit in the Hibernate area of the forum.

I am writing test cases for DAO's in a project. Rather than simulate the database access I really am going to a database.

My application will eventually be running on a MySql database, but I dont want to use that for testing. So at present when my test cases run spring calls derby which creates a new database. By using Hibernate's HBM2DDL.auto property I am creating my table structure and everything works fine happiness, right?

So my problem is (other than derby creating this annoying directory in my project for the database) derby seems very slow. At present my project is executing 81 tests of the DAO's in just over 8.5 seconds. Now I can live with 8.5 seconds delay in the build. The problem is I am only testing about 33% of the DAO. So I expect that number to probably triple. Again, 25 seconds delay during build is something I can live with. I am thinking down the road when I start testing other things like the service layer of my application (which trickles down to the DAO and DB) that number is going to go up. I really dont want to end up having a build which takes several minutes to execute!

So I have been looking at switching from derby (file based) to H2Database which according to their website (they wouldn't stretch the truth would they?) is the fastest in memory DB solution out there.

The problem I am running into is that when I execute my tests I get an error that my schema does not exist and my tests fail.

Has anyone gotten this to work? If not has anyone done something similar and can tell me what in memory DB they used and how?

Thanks



 
Seamus Minogue
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so I worked this out and thought I would share with all those who have suffered as I have suffered.

applicationContext.xml:




Games.hbm.xml:



JUnit Test Class:



The key seemed to be removing the catelog attribute of class tag in the hibernate-mapping file.

I dont really know why this broke things... But removing it fixed the problem. I dont know if its required when the application actually connects to my real database rather than this one in memory. This is part of a utility jar file and the mappings will be external to it when I actually deploy.

Anyway, my 81 tests went from like 8.5 seconds to execute down to 3.106 seconds. BIG improvement :-)

Hope this helps someone.

-Seamus







reply
    Bookmark Topic Watch Topic
  • New Topic