diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java index 87850638d..a47794298 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java @@ -45,15 +45,17 @@ class GetMapValue private final Val _map; private final Val _key; + private final String _alias; private ClassMetaData _meta = null; private Class _cast = null; /** * Constructor. Provide the map and key to operate on. */ - public GetMapValue(Val map, Val key) { + public GetMapValue(Val map, Val key, String alias) { _map = map; _key = key; + _alias = alias; } public ClassMetaData getMetaData() { @@ -111,7 +113,8 @@ class GetMapValue public void select(Select sel, ExpContext ctx, ExpState state, boolean pks) { - sel.select(newSQLBuffer(sel, ctx, state), this); + sel.select(newSQLBuffer(sel, ctx, state).append(" AS ").append(_alias), + this); } public void selectColumns(Select sel, ExpContext ctx, ExpState state, @@ -127,7 +130,7 @@ class GetMapValue public void orderBy(Select sel, ExpContext ctx, ExpState state, boolean asc) { - sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false); + sel.orderBy(_alias, asc, false); } private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) { diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java index 8fbcc4fae..d3f760a18 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java @@ -58,6 +58,7 @@ public class JDBCExpressionFactory private final ClassMapping _type; private final SelectConstructor _cons = new SelectConstructor(); + private int _getMapValueAlias = 0; /** * Constructor. Supply the type we're querying against. @@ -396,6 +397,7 @@ public class JDBCExpressionFactory } public Value getMapValue(Value map, Value arg) { - return new GetMapValue((Val) map, (Val) arg); + return new GetMapValue((Val) map, (Val) arg, + "gmv" + _getMapValueAlias++); } }