mirror of https://github.com/apache/openjpa.git
OPENJPA-708:
Sub-sub-query generates SQL with syntax error. Submitted By: Heath Thomann, based on Catalina's changes for trunk. git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@943663 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
11082c29d7
commit
f90ea1c743
|
@ -487,8 +487,13 @@ public class SelectImpl
|
|||
_joinSyntax = _parent._joinSyntax;
|
||||
}
|
||||
|
||||
if (_parent.getAliases() == null || _subPath == null)
|
||||
if (_parent.getAliases() == null || _subPath == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_parent._aliases.size() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not remove aliases for databases that use SYNTAX_DATABASE (oracle)
|
||||
if(_parent._joinSyntax != JoinSyntaxes.SYNTAX_DATABASE) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ public class TestSubquery
|
|||
public void setUp() {
|
||||
setUp(Customer.class, Customer.CustomerKey.class, Order.class,
|
||||
OrderItem.class, Employee.class, Dependent.class,
|
||||
DependentId.class, CLEAR_TABLES);
|
||||
DependentId.class, Magazine.class, Publisher.class, CLEAR_TABLES);
|
||||
}
|
||||
|
||||
static String[] querys = new String[] {
|
||||
|
@ -71,6 +71,16 @@ public class TestSubquery
|
|||
" (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)",
|
||||
"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:
|
||||
//"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)",
|
||||
|
|
Loading…
Reference in New Issue