}
@Test
public void testOptimisticLocking()
{
Manager manager = new Manager();
// create book record
Book book1 = new Book();
book1.setTitle("Gone");
// persist
book1 = manager.addBook(book1);
// update the title in memory
book1.setTitle("Gone with the wind");
// load original record
Book book2 = manager.getBook(book1.getBookId());
// update the title in memory
book2.setTitle("Test");
// persist book2
manager.update(book2);
// attempt to persist out of date book1
try
{
manager.update(book1);
fail("Test failed: Concurrent update of book, StaleObjectStateException not thrown when it should be.");
}
catch(StaleObjectStateException e)
{
assertEquals( "com.jcasey.model.Book", e.getEntityName());