|
[
Permalink
| « Hide
]
Christian Bauer added a comment - 04/Oct/06 06:10 AM
Changed to minor improvement. Obviously Hibernate doesn't know what you do in your SQL query, so you have to call flush().
Im not sure that i agree that this a minor improvement, since it says in the documentation :
"However, Hibernate does guarantee that the Query.list(..) will never return stale data; nor will they return the wrong data." This it obviously dos not guarantee. Yes you could just call flush, but this will make hibernate flush the whole session, not just the data needed for the query, wich might be a bit inefficient. Anyway Maybe you could add the possibility of adding querySpaces to the query. So that you can tell hibernate wich tables to flush in addition to the table of the result type. I would suggest something like the following in org.hibernate.impl.SQLQueryImpl /** * adds a table to be dirty checked and possibly flushed */ public SQLQuery addQuerySpace(String space) { if(querySpaces == null){ querySpaces = new ArrayList(); } querySpaces.add(space.toUpperCase()); return this; }[ This makes hibernate check for, and flush, the spaces added. I do not know if this breaks code other places in hibernate, but i do know that it fixes the problem statet by Frank. And it seems to work since i am able to run all my projects test with this addition to hibernate. it is still only an improvement and the doc for SQLQuery(!) documents synchronize and the need for it. (it is the same if you disable flushing then hibernate can also not guarantee that it will never return stale data)
Could you possibly provide me with a link to the documentation that you mention ? i do not seem to be able to find it.
Yes, i am fully aware that hibernate cant guarentee data consistency if the data is not flushed, hence the problem. As it is now its not possible for hibernate, and the user, to flush the affected tables, unless you flush the whole session. The solution i propose is a small feature, which would make it possible for the user to declare which tables are used and hence which tables hibernate need to check for dirty data. It *is* possible, ust used namedquery - for the programmatic api it is not, hence its an improvement.
Regarding the documenation, search for <synchronize>. (p.s. the native sql docs could probably be more explicit about synchronize) Yes, such functionality should be added to the SQLQuery interface. Something like SQLQuery.addSynchronize(String)...
|
||||||||||||||||||||||||||||||||||||||||||||||||