What I have:
I have integrate State Pattern in my app. That means that when I change state of some entity it may cause chain reaction. Means the states of related entities also may change, and than the states of related entities to those entities and so on.
Also I use Hibernate conversatetion, which means I use MANUL flush mode.
public void handler() {
session = beginHibernateConversation(); //open new transaction and new session (if it's needed)
entity.changeState(session); //call chain reaction
finishhibernateConversation(session); //manual flush, commit, and if it's needed - close session
}
What a problem:
When I use manual flush mode all changes are made to DB only on finishhibernateConversation(session) method.
I need use session.createQuery method inside changeState(session) method. But I can't see the actual entities states! Beacause all changes are stored in unflushed session and because session.createQuery doesn't matter about session context.
Question:
How to make session.createQuery consider session cache?
A little example:
For example I have Person - Job relationship (one-to-many). When I change state of one job to full time I need update all other related jobs (because person could work only on one full time job).
So, I do (inside of person UPDATE request)
job1.changeState('full time')- [inside the first method]
session.createQuery("from Job where person.id = (:id) state in (:states)").
The problem is that the second query isn't correct, because it doesn't consider about already changed state of job1