aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Kraus2014-03-13 17:00:29 (EDT)
committerGordon Yorke2014-03-14 13:46:21 (EDT)
commita7f8a2d0e990176208e4e8c71a409b7bfd477ded (patch)
tree0920990b1ecb8008f33a3bf7a953df6b44d268c3
parentb2b55f277dd1e1a2d2d2276413b453d59b28badc (diff)
downloadeclipselink.runtime-a7f8a2d0e990176208e4e8c71a409b7bfd477ded.zip
eclipselink.runtime-a7f8a2d0e990176208e4e8c71a409b7bfd477ded.tar.gz
eclipselink.runtime-a7f8a2d0e990176208e4e8c71a409b7bfd477ded.tar.bz2
Bug# 412582 - CriteriaBuilder.construct(...) fails with JoinType.LEFT and null - added this.setShouldBuildNullForNullPk(true) when left outer join is being added into ObjectLevelReadQuery Signed-off-by: Tomas Kraus <tomas.kraus@oracle.com>
-rw-r--r--foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ObjectLevelReadQuery.java6
-rw-r--r--jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/criteria/JUnitCriteriaSimpleTestSuite.java36
2 files changed, 39 insertions, 3 deletions
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ObjectLevelReadQuery.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ObjectLevelReadQuery.java
index a0187e4..ce76371 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ObjectLevelReadQuery.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/queries/ObjectLevelReadQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -666,7 +666,9 @@ public abstract class ObjectLevelReadQuery extends ObjectBuildingQuery {
*/
public void addNonFetchJoin(Expression target) {
getNonFetchJoinAttributeExpressions().add(target);
-
+ if (target.isObjectExpression() && ((ObjectExpression)target).shouldUseOuterJoin()) {
+ this.setShouldBuildNullForNullPk(true);
+ }
// Bug 2804042 Must un-prepare if prepared as the SQL may change.
// Joined attributes are now calculated in prePrepare.
setIsPrePrepared(false);
diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/criteria/JUnitCriteriaSimpleTestSuite.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/criteria/JUnitCriteriaSimpleTestSuite.java
index e56d372..cd4e998 100644
--- a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/criteria/JUnitCriteriaSimpleTestSuite.java
+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/criteria/JUnitCriteriaSimpleTestSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -81,6 +81,7 @@ import org.eclipse.persistence.testing.models.jpa.advanced.Address;
import org.eclipse.persistence.testing.models.jpa.advanced.AdvancedTableCreator;
import org.eclipse.persistence.testing.models.jpa.advanced.Employee;
import org.eclipse.persistence.testing.models.jpa.advanced.EmployeePopulator;
+import org.eclipse.persistence.testing.models.jpa.advanced.HugeProject;
import org.eclipse.persistence.testing.models.jpa.advanced.LargeProject;
import org.eclipse.persistence.testing.models.jpa.advanced.PhoneNumber;
import org.eclipse.persistence.testing.models.jpa.advanced.Project;
@@ -209,6 +210,7 @@ public class JUnitCriteriaSimpleTestSuite extends JUnitTestCase {
suite.addTest(new JUnitCriteriaSimpleTestSuite("testCriteriaBuilderConstructValidation"));
suite.addTest(new JUnitCriteriaSimpleTestSuite("testLiteralValidation"));
suite.addTest(new JUnitCriteriaSimpleTestSuite("testCompoundSelectionAliasValidation"));
+ suite.addTest(new JUnitCriteriaSimpleTestSuite("testEmptyLeftJoinInCriteriaQuery"));
return suite;
}
@@ -3168,6 +3170,38 @@ public class JUnitCriteriaSimpleTestSuite extends JUnitTestCase {
closeEntityManager(em);
}
+
+ // Bug# 412582 - CriteriaBuilder.construct(...) fails with JoinType.LEFT and null.
+ // Employee and HugeProject relation is one to one with no existing HugeProject instances.
+ // Those are conditions for bug# 412582 reproduction scenario.
+ /**
+ * Criteria query result container for <code>testEmptyLeftJoinInCriteriaQuery</code> test.
+ */
+ public static class EntityDTO {
+ public EntityDTO(Employee employee, HugeProject hugeProject) {}
+ }
+
+ // Bug# 412582 - CriteriaBuilder.construct(...) fails with JoinType.LEFT and null.
+ /**
+ * Verify criteria query with left outer join on empty table.
+ */
+ public void testEmptyLeftJoinInCriteriaQuery() {
+ EntityManager em = createEntityManager();
+ // Make sure that no HugeProject instance exists.
+ TypedQuery<Long> q1 = em.createQuery("SELECT COUNT(hp.id) FROM HugeProject hp", Long.class);
+ Long count = q1.getSingleResult();
+ assertEquals("There should be no HugeProject", 0, count.intValue());
+ // Execute left outer join on empty table as criteria query.
+ CriteriaBuilder builder = em.getCriteriaBuilder();
+ CriteriaQuery<EntityDTO> criteriaQuery = builder.createQuery(EntityDTO.class);
+ Root<Employee> rootEmployee = criteriaQuery.from(Employee.class);
+ Join<Employee, HugeProject> joinHugeProject = rootEmployee.join("hugeProject", JoinType.LEFT);
+ criteriaQuery.select(builder.construct(EntityDTO.class, rootEmployee, joinHugeProject));
+ TypedQuery<EntityDTO> query = em.createQuery(criteriaQuery);
+ List<EntityDTO> entities = query.getResultList();
+ closeEntityManager(em);
+ }
+
}