I am running the following code inside a stateful session bean. So I am not using Hibernate transactions. I do an explicit flush() when I want to data to be written to DB.
Code sample1:
Object myObj = ...; mySession_.save(myObj); //data goes to MY_TABLE //NOT invoking flush() String wClause = ....; List list = mySession_.createQuery("from " + MY_TABLE + " "+ wClause).list();
The list comes out as empty.
But if I insert flush() after save(),
Code sample2:
Object myObj = ...; mySession_.save(myObj); //data goes to MY_TABLE mySession_.flush(); String wClause = ....; List list = mySession_.createQuery("from " + MY_TABLE + " "+ wClause).list();
I get the row back in the list.
When Hibernate transactions are not used, does Hibernate always goes to Database directly for SELECTs and not to transient data in the session (that got inserted by previous saves)? I was hoping to use the session as a cache where I can allow clients of my program to insert, delete and select data at will and finally invoke flush() to persist the session after all the modifications.
Thanks.
Hibernate version: 3.1.3
Name and version of the database you are using: Oracle 10g
|