openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r881566 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
Date Tue, 17 Nov 2009 22:10:18 GMT
Author: ppoddar
Date: Tue Nov 17 22:10:18 2009
New Revision: 881566

URL: http://svn.apache.org/viewvc?rev=881566&view=rev
Log:
Support default projection for untyped result class, if possible.

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java?rev=881566&r1=881565&r2=881566&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
Tue Nov 17 22:10:18 2009
@@ -39,6 +39,7 @@
 import javax.persistence.criteria.Selection;
 import javax.persistence.criteria.SetJoin;
 import javax.persistence.criteria.Subquery;
+import javax.persistence.metamodel.EntityType;
 
 import org.apache.openjpa.persistence.test.AllowFailure;
 
@@ -1389,4 +1390,19 @@
                 cb.isTrue(cb.disjunction())));
         em.createQuery(c).getResultList();
     }
+    
+    public void testDefaultProjectionWithUntypedResult() {
+        CriteriaQuery cquery = cb.createQuery(); 
+        Root<Customer> customer = cquery.from(Customer.class);
+
+        //Get Metamodel from Root
+        EntityType<Customer> Customer_ = customer.getModel();
+
+        cquery.where(cb.equal(
+                customer.get(Customer_.getSingularAttribute("name", String.class)), 
+                cb.nullLiteral(String.class)));
+
+        Query q = em.createQuery(cquery);
+
+    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java?rev=881566&r1=881565&r2=881566&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
Tue Nov 17 22:10:18 2009
@@ -594,7 +594,9 @@
     
     protected boolean isDefaultProjection() {
         if (_selections == null) {
-            return getRoots().size() == 1 && getRoot().getModel().getJavaType() ==
_resultClass;
+            return getRoots().size() == 1 
+               && (getRoot().getModel().getJavaType() == _resultClass ||
+                   _resultClass == Object.class);
         } 
         if (_selections.size() != 1) {
             return false;



Mime
View raw message