[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2130?page=all ]
Steve Ebersole updated HHH-2130:
--------------------------------
Fix Version: 3.2.2
Assign To: Steve Ebersole
Priority: Major (was: Minor)
Yes, such functionality should be added to the SQLQuery interface. Something like
SQLQuery.addSynchronize(String)...
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
Assignee: Steve Ebersole
Fix For: 3.2.2
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