This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing A Hibernate DAO Delete Method

 
Jason Ferguson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, I'm using a Spring 2.5/Hibernate 3.3.2 combination with the JUnit annotations.

I'm trying to unit test a DAO's delete method. Here is the code:



The second call to manufacturer.loadById(311) should obviously throw an exception but doesn't. I'm obviously being stupid here about the way transactions work, can anyone help me?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason,
Don't you need to call manufacturerDao.flush() to force the delete to get to the database?

I'm going to move this to the Hibernate question since a Hibernate expert is going to be more help here than a testing one.
 
Jason Ferguson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Jason,
Don't you need to call manufacturerDao.flush() to force the delete to get to the database?

I'm going to move this to the Hibernate question since a Hibernate expert is going to be more help here than a testing one.


One word response: D'OH!

The idjits who originally wrote the DAO didn't put a flush method into their generic DAO, and I wasn't thinking about it.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the Dao doesn't have to have the flush() as it would be called at the commit of the transaction anyway.

But you would need to in your unit test because you are kind of doing code that wouldn't happen in a live environment.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic