Author: fancy
Date: Sun Aug 31 16:53:36 2008
New Revision: 690823
URL: http://svn.apache.org/viewvc?rev=690823&view=rev
Log:
OPENJPA-708 sub-sub-query generates SQL with syntax error
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=690823&r1=690822&r2=690823&view=diff
==============================================================================
---
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
(original)
+++
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
Sun Aug 31 16:53:36 2008
@@ -576,7 +576,10 @@
if (_parent.getAliases() == null || _subPath == null)
return;
-
+
+ if (_parent._aliases.size() <= 1)
+ return;
+
// resolve aliases for subselect from parent
Set<Map.Entry> entries = _parent.getAliases().entrySet();
for (Map.Entry entry : entries) {
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java?rev=690823&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Magazine.java
Sun Aug 31 16:53:36 2008
@@ -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;
+
[EMAIL PROTECTED]
+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;
+ }
+}
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java?rev=690823&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Publisher.java
Sun Aug 31 16:53:36 2008
@@ -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;
+
[EMAIL PROTECTED]
+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;
+ }
+}
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java?rev=690823&r1=690822&r2=690823&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
Sun Aug 31 16:53:36 2008
@@ -32,7 +32,8 @@
public void setUp() {
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[] {
@@ -68,6 +69,16 @@
" (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)",