mueller
Mar 15th, 2008, 10:48 AM
I really love how Spring makes unit testing so easy with dependency injection and database testing infrastructure like the AbstractTransactionalDataSourceSpringContextTests class. However, I'm having some trouble testing inserting data using hibernate.
If I want to test an addThing method, this is how I'd imagine doing it:
long id = thingDao.addThing(oldThing);
Thing newThing = thingDao.getThing(id);
assertEquals("Name should be same", oldThing.getName(), newThing.getName());
For code like above, I'd get an org.hibernate.NonUniqueObjectException stating "a different object with the same identifier value was already associated with the session." So how do I do the very necessary test of seeing if a row was inserted properly?
If I want to test an addThing method, this is how I'd imagine doing it:
long id = thingDao.addThing(oldThing);
Thing newThing = thingDao.getThing(id);
assertEquals("Name should be same", oldThing.getName(), newThing.getName());
For code like above, I'd get an org.hibernate.NonUniqueObjectException stating "a different object with the same identifier value was already associated with the session." So how do I do the very necessary test of seeing if a row was inserted properly?