When a Book object is persisted, a trigger on Insert runs to create a transaction record (in a separate table).
When I create an instance of Book and save it, I'd expect to see this record in the transactions()
array, but it's continually empty.
Book book = new Book("Moby Dick", "Melville", "hardcover");
book = bookRepository.saveAndFlush(book);
if( book != null)
assertTrue("There is no transaction history", book.transactions().size() > 0 );
This always fails. So does this (my gyrations to try to get the data reloaded):
public int addBook()
{
int bookID;
Book book = new Book("Moby Dick", "Melville", "hardcover");
book = bookRepository.saveAndFlush(book);
if( book != null)
bookID = book.getID();
return bookID;
}
@Test
public void testNewBookTrans()
{
int aBook = addBook();
bookRepository.findAll();
transactionRepository.findAll();
Book book = bookRepository.findOne(bookID);
if( book != null )
assertTrue("Still no transactions", book.getTransactions().size() > 0);
}
Yet, if I let this test fail, restart JUnit and then query the same book, it has the transaction that the trigger added.
So, there must be some way to invalidate or reload the db cache but I'm not seeing it.