views:

42

answers:

1

Hello everyone,

I'm trying to break the question down to something simple.

I use nhibernate to get a list of entities via a criteria call. After that I'll update some entites and add one entity which I save (session.SaveOrUpdate(entity)). When I get a list with a criteria again I do get the entities that were changed (with changed values) in my list but not the entity I added. I read that the criteria doesn't use the session cash but "will always result in a SQL query / call to the DB". Well, somehow the entities that I changed are from the session cache (I didn't commit yet and nothing has been written to the database) but the Criteria doesn't "find" my newly added entity. Is it possible to make the Criteria get all entities from the cache (i know the added entity is there cause i can check the keys in the statistics-entitykeys list)?

P.s.:It's somehow strange that I can load a list of entities, ADD AND SAVE some, get the "whole list" again and still only get the ones that were in there the first time. Do I really need to commit to get the full list?

P.s.s: I don't want to use the second level cache cause that would mean i commit changes made in another session too when I "commit", right?

A: 

Flush your changes and you'll see the newly added entity in the list. You don't have to Commit, but Criteria returns the results of a SQL query, it doesn't magically go through the caches retrieving entities that might be included in the results,

Diego Mijelshon
okay. I tried that and then i get the problem, that after the commit flush the used tables are locked till either a commit or a rollback. you are right that the criterias return the correct results including the new entities but locking whole tables will the user decides to save or not isn't really an option.
Jan
You never mentioned this was part of an interactive windows client workflow, nor that there was an intermediate step.
Diego Mijelshon
sorry. i would have voted your answer up but i don't have enough reputation to do that. seems like what i am trying to do isn't really supported that easily and i will have to manage non-comitted entities on my own.
Jan