mirror of https://github.com/apache/openjpa.git
OPENJPA-1974: Applied to 2.1.x Rick's changes from trunk (2.2.x)
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@1341755 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f41f79360b
commit
4e9fd21084
|
@ -154,7 +154,7 @@ public class SelectImpl
|
|||
private Set _eagerKeys = null;
|
||||
|
||||
// subselect support
|
||||
private List _subsels = null;
|
||||
private List<SelectImpl> _subsels = null;
|
||||
private SelectImpl _parent = null;
|
||||
private String _subPath = null;
|
||||
private boolean _hasSub = false;
|
||||
|
@ -2022,7 +2022,7 @@ public class SelectImpl
|
|||
return -1;
|
||||
|
||||
// not found; create alias
|
||||
i = aliasSize(null);
|
||||
i = aliasSize(false, null);
|
||||
// System.out.println("GetTableIndex\t"+
|
||||
// ((_parent != null) ? "Sub" :"") +
|
||||
// " created alias: "+
|
||||
|
@ -2125,19 +2125,19 @@ public class SelectImpl
|
|||
_tables.put(alias, tableString);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate total number of aliases.
|
||||
*
|
||||
* From 1.2.x
|
||||
*/
|
||||
private int aliasSize(SelectImpl fromSub) {
|
||||
int aliases = (_parent == null) ? 0
|
||||
: _parent.aliasSize(this);
|
||||
private int aliasSize(boolean fromParent, SelectImpl fromSub) {
|
||||
int aliases = (fromParent || _parent == null) ? 0 : _parent.aliasSize(false, this);
|
||||
aliases += (_aliases == null) ? 0 : _aliases.size();
|
||||
if (_subsels != null) {
|
||||
SelectImpl sub;
|
||||
for (int i = 0; i < _subsels.size(); i++) {
|
||||
sub = (SelectImpl) _subsels.get(i);
|
||||
for (SelectImpl sub : _subsels) {
|
||||
if (sub != fromSub)
|
||||
aliases += sub.aliasSize(null);
|
||||
aliases += sub.aliasSize(true, null);
|
||||
}
|
||||
}
|
||||
return aliases;
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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.jpql;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||
import org.apache.openjpa.persistence.util.EagerEmbed;
|
||||
import org.apache.openjpa.persistence.util.EagerEmbedRel;
|
||||
import org.apache.openjpa.persistence.util.EagerEntity;
|
||||
|
||||
public class TestOneToManySubQuery extends SingleEMFTestCase {
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp(CLEAR_TABLES, EagerEntity.class, EagerEmbed.class, EagerEmbedRel.class);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
try {
|
||||
assertEquals(0, em.createQuery(
|
||||
"SELECT e FROM EagerEntity e WHERE EXISTS (SELECT e1 FROM e.eagerSelf e1 WHERE e1.id = 0)"
|
||||
+ " OR EXISTS (SELECT e1 FROM e.eagerSelf e1 WHERE e1.id = 1)", EagerEntity.class).getResultList()
|
||||
.size());
|
||||
|
||||
} finally {
|
||||
em.close();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ import javax.persistence.Embedded;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
@Entity
|
||||
|
@ -45,6 +46,9 @@ public class EagerEntity {
|
|||
|
||||
@ElementCollection(fetch=FetchType.EAGER)
|
||||
private List<EagerEmbed> eagerEmbedColl;
|
||||
|
||||
@OneToMany(fetch=FetchType.EAGER)
|
||||
private List<EagerEntity> eagerSelf;
|
||||
|
||||
@Transient
|
||||
private String transField;
|
||||
|
|
Loading…
Reference in New Issue