Making new session objects available for Object Level Query
Sometimes you may need to create data in the TopLink session to support your test scenarios. To make those newly created objects available for object level queries down the road in your execution patch, you need to do the following:
- register the new object into the session using UnitOfWork.registerNewObject()
- call alwaysConformResultsInUnitOfWork.
Remember that, if you read Part 1 of this series, the new object will not be saved into database. The changes are being rolled back for each test case as described in Part 1.
Making new session objects available for non-Object Level Query
If there are non-object level queries in your application, e.g. Named Query, and you want to create test data for the query, then do the following:
- register the new object into the session using UnitOfWork.registerNewObject()
- call UnitOfWork.writeChanges().
1 comment:
If writechanges() can only used for once, how useful is it in continuous integration environment where bunch of tests are running? I would rather use other methods, e.g. DBunit or mock objects.
Post a Comment