mirror of https://github.com/apache/openjpa.git
OPENJPA-51 A non-correlated subquery resulting SQL syntax error
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@676787 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
434319cfee
commit
89695ec253
|
@ -582,7 +582,8 @@ public class SelectImpl
|
|||
for (Map.Entry entry : entries) {
|
||||
Object key = entry.getKey();
|
||||
Integer alias = (Integer) entry.getValue();
|
||||
if (key.toString().indexOf(_subPath) != -1) {
|
||||
if (key.toString().indexOf(_subPath) != -1 ||
|
||||
_parent.findTableAlias(alias) == false) {
|
||||
if (_aliases == null)
|
||||
_aliases = new HashMap();
|
||||
_aliases.put(key, alias);
|
||||
|
@ -602,7 +603,8 @@ public class SelectImpl
|
|||
for (Map.Entry entry : entries) {
|
||||
Object key = entry.getKey();
|
||||
Integer alias = (Integer) entry.getValue();
|
||||
if (key.toString().indexOf(_subPath) != -1) {
|
||||
if (key.toString().indexOf(_subPath) != -1 ||
|
||||
_parent.findTableAlias(alias) == false) {
|
||||
_parent.removeAlias(key);
|
||||
|
||||
Object tableString = _parent.getTables().get(alias);
|
||||
|
@ -612,6 +614,16 @@ public class SelectImpl
|
|||
}
|
||||
}
|
||||
|
||||
private boolean findTableAlias(Integer alias) {
|
||||
// if alias is defined and referenced, return true.
|
||||
String value = "t" + alias.toString() + ".";
|
||||
if (_tableAliases != null)
|
||||
return _tableAliases.containsValue(value) &&
|
||||
_tables.containsKey(alias);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
public Map getAliases() {
|
||||
return _aliases;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,9 @@ public class TestSubquery
|
|||
}
|
||||
|
||||
static String[] querys = new String[] {
|
||||
"select o1.oid from Order o1 where o1.oid in " +
|
||||
" (select distinct o.oid from OrderItem i, Order o" +
|
||||
" where i.quantity > 10 and o.amount > 1000 and i.lid = o.oid)" ,
|
||||
"select o.oid from Order o where o.customer.name =" +
|
||||
" (select max(o2.customer.name) from Order o2" +
|
||||
" where o.customer.cid.id = o2.customer.cid.id)",
|
||||
|
|
Loading…
Reference in New Issue