openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fay Wang <fyw...@yahoo.com>
Subject Unpredictable set clause in generated sql
Date Fri, 02 May 2008 23:31:23 GMT
Hi,
      Our application requires the push-down sql from named/dynamic query be the same each
time a same JPQL is executed. In the following JPQL example,
	
      query="UPDATE BasicA t set t.name= ?1, t.age = ?2 WHERE t.id = ?3"

      we observe two different push-down sql could be generated:
      
      UPDATE PDQBasicA t0 SET name = ?, age = ? WHERE (t0.id = ?)

      UPDATE PDQBasicA t0 SET age = ?, name = ? WHERE (t0.id = ?)

      This unpredictable behavior breaks our application. The indeterministic ordering of
the update list is due to the indeterministic ordering provided by HashMap and HashSet in
QueryExpressions and JPQLExpressionBuilder, respectively.

      When the HashMap is changed to LinkedHashMap and HashSet to LinkedHashSet, the access
order based on insertion will be preserved and the generated push-down sql will have predictable
ordering of update list. Is there an alternative way to address this issue?

      Should a JIRA issue be open to fix this problem? Any comment is appreciated.

	In QueryExpressions:
    /**
     * Add an update.
     */
    public void putUpdate(Path path, Value val) {
        if (updates == Collections.EMPTY_MAP)
            updates = new HashMap();  <== change HashMap to LinkedHashMap
        updates.put(path, val);
    }

In JPQLExpressionBuilder:

    JPQLNode[] findChildrenByID(int id) {
        Collection set = new HashSet(); <== change HashSet to LinkedHashSet
        findChildrenByID(id, set);
        return (JPQLNode[]) set.toArray(new JPQLNode[set.size()]);
    }

-Fay


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

Mime
View raw message