mirror of https://github.com/apache/openjpa.git
OPENJPA-708 sub-sub-query generates SQL with syntax error
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@690823 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aa1516f04b
commit
650161a887
|
@ -577,6 +577,9 @@ public class SelectImpl
|
||||||
if (_parent.getAliases() == null || _subPath == null)
|
if (_parent.getAliases() == null || _subPath == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (_parent._aliases.size() <= 1)
|
||||||
|
return;
|
||||||
|
|
||||||
// resolve aliases for subselect from parent
|
// resolve aliases for subselect from parent
|
||||||
Set<Map.Entry> entries = _parent.getAliases().entrySet();
|
Set<Map.Entry> entries = _parent.getAliases().entrySet();
|
||||||
for (Map.Entry entry : entries) {
|
for (Map.Entry entry : entries) {
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.persistence.query;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Magazine implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name="id")
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
@Column(name="name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name="date_published")
|
||||||
|
private Date datePublished;
|
||||||
|
|
||||||
|
@ManyToOne(fetch=FetchType.LAZY)
|
||||||
|
@JoinColumn(name="id_publisher")
|
||||||
|
private Publisher idPublisher;
|
||||||
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Publisher getIdPublisher() {
|
||||||
|
return this.idPublisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdPublisher(Publisher idPublisher) {
|
||||||
|
this.idPublisher = idPublisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDatePublished() {
|
||||||
|
return datePublished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatePublished(Date datePublished) {
|
||||||
|
this.datePublished = datePublished;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.persistence.query;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Publisher implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name="id")
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
@Column(name="name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy="idPublisher")
|
||||||
|
private Set<Magazine> magazineCollection;
|
||||||
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Magazine> getMagazineCollection() {
|
||||||
|
return this.magazineCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMagazineCollection(Set<Magazine> magazineCollection) {
|
||||||
|
this.magazineCollection = magazineCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,8 @@ public class TestSubquery
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
setUp(Customer.class, Customer.CustomerKey.class,
|
setUp(Customer.class, Customer.CustomerKey.class,
|
||||||
Order.class, OrderItem.class, CLEAR_TABLES);
|
Order.class, OrderItem.class,
|
||||||
|
Magazine.class, Publisher.class, CLEAR_TABLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String[] querys = new String[] {
|
static String[] querys = new String[] {
|
||||||
|
@ -68,6 +69,16 @@ public class TestSubquery
|
||||||
" (select sum(o2.amount) from c.orders o2)",
|
" (select sum(o2.amount) from c.orders o2)",
|
||||||
"select o1.oid, c.name from Order o1, Customer c where o1.amount = " +
|
"select o1.oid, c.name from Order o1, Customer c where o1.amount = " +
|
||||||
" any(select o2.amount from in(c.orders) o2)",
|
" any(select o2.amount from in(c.orders) o2)",
|
||||||
|
"SELECT p, m "+
|
||||||
|
"FROM Publisher p "+
|
||||||
|
"LEFT OUTER JOIN p.magazineCollection m "+
|
||||||
|
"WHERE m.id = (SELECT MAX(m2.id) "+
|
||||||
|
"FROM Magazine m2 "+
|
||||||
|
"WHERE m2.idPublisher.id = p.id "+
|
||||||
|
"AND m2.datePublished = "+
|
||||||
|
"(SELECT MAX(m3.datePublished) "+
|
||||||
|
"FROM Magazine m3 "+
|
||||||
|
"WHERE m3.idPublisher.id = p.id)) ",
|
||||||
// outstanding problem subqueries:
|
// 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(o) from Order o)",
|
||||||
//"select o from Order o where o.amount > (select count(o2) from Order o2)",
|
//"select o from Order o where o.amount > (select count(o2) from Order o2)",
|
||||||
|
|
Loading…
Reference in New Issue