Before a JDBC operation, flush the Hibernate Session (includes TSE example code)
Mixing code in one and the same transaction that uses an Object-Relational Mapper with code that doesn't, can cause issues with data not being available in the underlying database when it should be. Since this is a situation I come across once every now and then, I figured it would be helpful for all if I write down my solution to this problem.
In short: what I will present in the remainder of this post is an aspect that triggers the underlying persistence mechanism (JPA, Hibernate, TopLink) to send any dirty data to the database.
I presented this aspect by the way during one of my sessions at The Spring Experience last December and this post also has the source code for those of you…