[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2130?page=c...
]
Timm Kristensen commented on HHH-2130:
--------------------------------------
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.
SQLQuery does not autoflush all entities used in the query
----------------------------------------------------------
Key: HHH-2130
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2130
Project: Hibernate3
Type: Improvement
Components: query-sql, core
Versions: 3.1.3
Environment: Hibernate version 3.1.3, Oracle v 9.2
Reporter: Frank Tolstrup
Priority: Minor
I have a problem with autoflushing on native SQL queries. The scenario is:
1. I use a complex sql with a lot of joined tables
2. I change some of the associated objects from the result (but not the returned types).
3. I do the same sql as in step 1
The problem is that the autoflush before the sql in step 3 only flushes changes in
objects of the class returned by the sql, NOT all other objects used in the query.
If I change the query in step 3 to HQL it works as I would expect and flushes all objects
included in the query.
It says in the hibernate documentation (section 10.10 Flushing the session), that
"However, Hibernate does guarantee that the Query.list(..) will never return stale
data; nor will they return the wrong data."
This seems not to be the case with native SQL queries.
The SQL query: (flushes only changed Tjeneste objects)
SQLQuery sqlQuery = session.createSQLQuery
("SELECT /*+ use_nl(a av) */ {t.*}"
+"FROM TJENESTE t, "
+"TJENESTEVERSION tv, "
+"ALLOKERING a, "
+"ALLOKERINGSVERSION av "
+"WHERE t.TJENESTE_ID = tv.TJENESTE_ID "
+"AND av.plan_id = 0 "
+"AND av.slettet = 0 "
+"AND av.allokering_id = a.allokering_id "
+"AND a.medarbejder_id =:medarb "
+"AND tv.tjeneste_id = av.tjeneste_id "
+"AND tv.fra_tid >= :fraTid "
+"AND tv.til_tid <= :tilTid"
);
The HQL query: (flushes changed objects of classes Tjeneste, TjenesteVersion,
AllokeringsVersion, Allokering)
("SELECT av.tjeneste "
+" FROM"
+" TjenesteVersion tv,"
+" AllokeringsVersion av"
+" WHERE "
+" av.plan.id = 0"
+" and av.slettet = 0"
+" and av.allokering.medarbejder.id = :medarb"
+" and tv.tjeneste = av.tjeneste"
+" and tv.plan.id = 0"
+" and tv.fraTid >= :fraTid"
+" and tv.tilTid <= :tilTid"
It would be enough to add a method to SQLQuery to add entities to the QuerySpace that
will be flushed before the query is executed. An api method to match the
"<synchronize>" in a named query.
Regards,
Frank
PS: See the thread in the Hibernate user forum:
http://forum.hibernate.org/viewtopic.php?p=2324846
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira