diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java index 35d42f2b1..41afc02df 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java @@ -618,8 +618,10 @@ public class SelectImpl // if alias is defined and referenced, return true. String value = "t" + alias.toString() + "."; if (_tableAliases != null) - return _tableAliases.containsValue(value) && - _tables.containsKey(alias); + if (_tableAliases.containsValue(value)) + return _tables.containsKey(alias); + else + return _joins != null; else return true; } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java index f0d15c475..33f4b6d46 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java @@ -66,6 +66,8 @@ public class TestSubquery " and (select min(o2.amount) from Customer c, in(c.orders) o2)", "select o.oid from Customer c, in(c.orders)o where o.amount >" + " (select sum(o2.amount) from c.orders o2)", + "select o1.oid, c.name from Order o1, Customer c where o1.amount = " + + " any(select o2.amount from in(c.orders) o2)", // outstanding problem subqueries: //"select o from Order o where o.amount > (select count(o) from Order o)", //"select o from Order o where o.amount > (select count(o2) from Order o2)",