Index: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java =================================================================== --- openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java (revision 529721) +++ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java (working copy) @@ -234,7 +234,7 @@ * updateClause and isolationLevel hints */ protected String getForUpdateClause(JDBCFetchConfiguration fetch, - boolean forUpdate) { + boolean forUpdate, boolean subselect) { int isolationLevel; StringBuffer forUpdateString = new StringBuffer(); try { @@ -245,11 +245,11 @@ else isolationLevel = conf.getTransactionIsolationConstant(); - if (!forUpdate) { + if (!forUpdate && !subselect) { // This sql is not for update so add FOR Read Only clause forUpdateString.append(" ").append(forReadOnlyClause) .append(" "); - } else { + } else if(forUpdate) { switch(db2ServerType) { case db2ISeriesV5R3AndEarlier: @@ -362,8 +362,23 @@ public SQLBuffer toSelect(Select sel, boolean forUpdate, JDBCFetchConfiguration fetch) { - SQLBuffer buf = super.toSelect(sel, forUpdate, fetch); - + sel.addJoinClassConditions(); + boolean update = forUpdate && sel.getFromSelect() == null; + boolean subSelect = sel.getParent() != null; + SQLBuffer select = getSelects(sel, false, update); + SQLBuffer ordering = null; + if (!sel.isAggregate() || sel.getGrouping() != null) + ordering = sel.getOrdering(); + SQLBuffer from; + if (sel.getFromSelect() != null) + from = getFromSelect(sel, forUpdate); + else + from = getFrom(sel, update); + SQLBuffer where = getWhere(sel, update); + SQLBuffer buf = toOperation(getSelectOperation(fetch), select, from, + where,sel.getGrouping(),sel.getHaving(), ordering, + sel.isDistinct(),sel.getStartIndex(),sel.getEndIndex(), + getForUpdateClause(fetch, forUpdate,subSelect)); if (sel.getExpectedResultCount() > 0) { buf.append(" ").append(optimizeClause).append(" ") .append(String.valueOf(sel.getExpectedResultCount())) @@ -414,4 +429,6 @@ return sqle.getMessage(); } } + + }