From 053ad36618e2671bb5896023be8554e28d575965 Mon Sep 17 00:00:00 2001 From: Catalina Wei Date: Fri, 8 Aug 2008 06:46:29 +0000 Subject: [PATCH] OPENJPA-681 Subquery generates SQL with syntax error git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@683876 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java | 6 ++++-- .../org/apache/openjpa/persistence/query/TestSubquery.java | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) 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)",