tags:

views:

46

answers:

4

Just curious to know if there is any framework that helps to test the hibernate mapping schema.

I've found ORMUnit, used in "POJOs in Action", but it doesn't seem to be in use much. Is there any other framework that people use to make sure that the classes are mapped properly to the database schema, or is this something that people don't really need?

A: 

You could try DBUnit, to test your data access layer as a whole.

DBUnit

lucas1000001
A: 

DBUnit is used for all kinds of database-related testing, that would include making sure your entities are mapped appropriately. Basically you can specify a dataset specifying how you want the database to be set up prior to the test, and another dataset specifying how the database should look at the end of the test, and DBUnit will insert the set up data, run your test, and compare your expected results to the actual results. ORMUnit sounds interesting, though. I haven't checked it out yet, but Chris Richardson is a smart guy, it might be worth looking into.

Nathan Hughes
+1  A: 

Its the type of thing you dont really need. If you test your persistence layer, you are implicitly testing your mapping. You are validating that all columns in the mapping map to columns in the db, that the relationships are set up correctly etc. Any IDE should validate your mapping against the schema, so you know your mapping is syntactically correct.

Testing also gives you a backup for understanding your persistence semantics, e.g. given my cascade settings, will the delete cascade down? Will creating an orphan cause it to be deleted, etc...When I worked with hibernate most tests were in the persistence layer, for exactly this reason.

hvgotcodes
+1  A: 

Have a look at Unitils: http://www.unitils.org/

You can use the following:

HibernateUnitils.assertMappingWithDatabaseConsistent();

See the documentation on the website on how to set up Hibernate + Unitils.

Wilhelm Kleu