0

I have spring+hibernate project, I want to write Unit test case for DAO layers, Currently I am using HSqldb's in memory DB to test it. (I referred this )

In project, IDs are provided by sequences, As I am using in-memory DB, during test sequence are not presents so it was falling, For workaround, I have created different set of hbm files without sequence(and put them test's resource folder). Is there any better way to handle this, as keeping duplicate hbm file does look good to me. Any suggestion would be appreciated

Vikas Singh
  • 2,838
  • 5
  • 17
  • 32

2 Answers2

2

If you need a sequence in your test database, just create it.

Also, make sure you have the correct database dialect configured with Hibernate.

Consult the following related questions for details:

Community
  • 1
  • 1
Sam Brannen
  • 29,611
  • 5
  • 104
  • 136
0

Holding complete copies of the HBM files doesn't sound like a good idea (one of the principles I strongly believe in is the "DRY" principle). The solution I'd suggest (unless there's a better solution from the Hibernate side) is to edit the HBM file in the "@before" method, in order to change just the different bits. I'm more of a .Net guy, and I know that in In .Net there's a library called FluentNHibernate that allows the generate (and I assume that also edit existing) hbm at runtime. I'm not sure if there's something similar in Java, but you can also fallback for manipulating the hbm as an XML file.

Arnon Axelrod
  • 1,444
  • 2
  • 13
  • 21