简体   繁体   中英

Hibernate testing with DBUnit without hbm files

I'm trying to test app which uses hibernate with DBUnit. My tests run on an in-memory db with a create-drop strategy.

I keep getting NoSuchTableException when DBunit tries to feed the db. All the examples I found on the web of this combination (Hibernate and DBUnit) had the database structure declared in *hbm files.

Is it mandatory to have hbm files in order to integrate Hibernate with DBUnit?

Cheers!

You don't need to have hbm files.

What's happening is that DBUnit creates the in memory DB, but it's a clean DB. So it is unable to load the data.

As part of your setup code, you need to initialize Hibernate before you load the data. You can do this by issuing a call to select 1 through the Hibernate API. This will force Hibernate to create the tables, then you call your DBUnit setup which will then populate them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM