[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2130) SQLQuery does not autoflush all entities used in the query

Max Rydahl Andersen (JIRA) noreply at atlassian.com
Wed Oct 4 08:58:25 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2130?page=comments#action_24707 ] 

Max Rydahl Andersen commented on HHH-2130:
------------------------------------------

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)



> 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.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list