Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6706361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:30:42+00:00 2026-05-26T07:30:42+00:00

I am wondering what people have found their best practice to be for testing

  • 0

I am wondering what people have found their best practice to be for testing Hibernate mappings and queries ?

This cannot be done with Unit Testing, so my experience has been to write Integration Tests that solely tests the DAO layer downwards. This way I can fully test each Insert / Update / Delete / ReadQueries without testing the full end-to-end solution.

Whenever the Integration test suite is run it will:-

  1. Drop and re-create the database.
  2. Run an import SQL script that contains a subset of data.
  3. Run each test in a Transactional context that rolls back the transaction. Therefore it can be run multiple times as an independent test, or and as part of a suite, and the same result is returned as the database is always in a known state.

I never test against a different “in memory” database, as there is always an equivalent development database to test against.

I have never had the need to use DBUnit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:30:43+00:00Added an answer on May 26, 2026 at 7:30 am

    Never use DbUnit for this. It’s way too much overhead for this level of testing.

    Especially if you’re using Spring in your app, check out the Spring Test Framework to help manage your data-access tests, particularly the transaction management features.

    An “equivalent development database” is fine, but an in-memory H2 database will blow away anything else for speed. That’s important because, while the unit/integration status of these tests may be contested, they’re tests you want to run a lot, so they need to be as fast as possible.

    So my DAO tests look like this:

    1. Spring manages the SessionFactory and TransactionManager.
    2. Spring handles all transactions for test methods.
    3. Hibernate creates the current schema in an in-memory H2 database.
    4. Test all the save, load, delete, and find methods, doing field-for-field comparison on before and after objects. (E.g. create object foo1, save it, load it as foo2, verify foo1 and foo2 contain identical values.)

    Very lightweight and useful for quick feedback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering what other people have found to be the best graphing libraries/plug-ins/gems
I have been wondering about how people manage their strings if they are likely
I was wondering how other people implemented this scenario. I have an internal rails
I was wondering if people would share their best practices / strategies on handling
I was discussing this at work, and was wondering where people start their designs?
just wondering what tips people have for avoiding game synchronisation issues in multiplayer games
I'm wondering how people are currently resetting their data / cleaning up test remnants
I have seen other people who have had this question, but most of the
I have done automated UI testing before on a major WPF project and it
This is more of a general question as I have found relatively little information

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.