HI!
We are evaluating Hibernate (3.2.0CR1) for a large ERP app, that uses our own OR mapper at the moment.
One of the biggest advantages of Hibernate over own OR mapper would be the automatic flush on commit, resulting in minimal lock time (updated, but not yet committed rows).
So, I set FlushMode.COMMIT. Also, using EH 2nd level cache.
Now, if I change a property, save and then do a query without that property in the where clause, it finds the object and I get the up-to-date object with the changed property. This is good.
But when I use the changed property in the where clause, it will not find the object, because the
a) the change is not yet reflected in the database
b) Hibernate Query only runs on the DB, not on the cache
I have read relevant docs, went through the tutorial and searched in the forum. So, I learned, that this is not a bug, but a well-documented behavior.
My question is: Why?
Why does Hibernate not search in the DB *and* the cache and returns results from both?
Is this a planned feature?
Thanks!
Thomas
Code:
-------
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.setFlushMode(FlushMode.COMMIT);
Person aPerson = (Person) session.load(Person.class, personId);
aPerson.setAge(20);
session.save(aPerson);
List persons = session.createQuery("from Person where age = 20").list();
for (int i = 0; i < persons.size(); i++) {
Person thePerson = (Person) persons.get(i);
System.out.println("Person: " + thePerson.getFirstname() +
" " + thePerson.getLastname() + ", " + thePerson.getAge());
}
session.getTransaction().commit();