nathanmoon wrote:
Did you commit the transaction? The exception won't get thrown in the saveOrUpdate - it will be thrown in the commit.
Good question, that. My colleague and I were just talking about it. Because this is a test suite, once the data has been 'inserted', we rollback the transaction in order to facilitate further tests.
However I'll reiterate that our expectation was that exceptions such as trying to insert a null value into a not-null field are thrown during the insert.
This is primarily because of the 'insert then select' scenario. it is not uncommon for an object to be created in the database and then selected again all within the same transaction. The data hasn't been committed but the insert is deemed to have been done.
Thinking about when we're not testing, if the exception isn't thrown until the commit, which is done right at the end of the whole process, then the user has potentially finished what they're doing and all of a sudden there's an exception thrown. Also in a longer business process, you might surround the insert action you're performing with a try/catch for the exception you're looking for. But if it isn't thrown until some later time, then you're code gets broken. Doesn't seem right...