openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fa...@apache.org
Subject svn commit: r954007 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-jdbc/src/main/resources/...
Date Sat, 12 Jun 2010 14:05:44 GMT
Author: fancy
Date: Sat Jun 12 14:05:43 2010
New Revision: 954007

URL: http://svn.apache.org/viewvc?rev=954007&view=rev
Log:
OPENJPA-1696: Type discriminator for polymorphic queries limited to Single Table inheritance

Added:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualTypeExpression.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualTypeExpression.java
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ExpContext.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Param.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Type.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
    openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/exps/localizer.properties
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestDefaultInheritanceStrategy.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/TestInheritanceTypeJoinedQuery.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
Sat Jun 12 14:05:43 2010
@@ -42,7 +42,9 @@ import org.apache.openjpa.jdbc.kernel.ex
 import org.apache.openjpa.jdbc.kernel.exps.SQLValue;
 import org.apache.openjpa.jdbc.kernel.exps.Val;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.Discriminator;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.meta.strats.NoneDiscriminatorStrategy;
 import org.apache.openjpa.jdbc.meta.strats.VerticalClassStrategy;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.Table;
@@ -345,6 +347,11 @@ public class JDBCStoreQuery 
             if (verts.length == 1 && subclasses)
                 subclassBits.set(sels.size());
 
+            Discriminator disc = mappings[i].getDiscriminator();
+            if (mappings.length > 1 && disc != null && disc.getColumns().length
== 0 &&
+                disc.getStrategy() instanceof NoneDiscriminatorStrategy)
+                ctx.tpcMeta = mappings[i];
+
             // create criteria select and clone for each vert mapping
             sel = ((JDBCExpressionFactory) facts[i]).getSelectConstructor().
                 evaluate(ctx, null, null, exps[i], states[i]);

Added: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualTypeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualTypeExpression.java?rev=954007&view=auto
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualTypeExpression.java
(added)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualTypeExpression.java
Sat Jun 12 14:05:43 2010
@@ -0,0 +1,90 @@
+/*
+ * 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.jdbc.kernel.exps;
+
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+
+/**
+ * Compares two entity types.
+ *
+ * @author Catalina Wei
+ */
+class EqualTypeExpression
+    extends CompareEqualExpression {
+
+    /**
+     * Constructor. Supply values to compare.
+     */
+    public EqualTypeExpression(Val val1, Val val2) {
+        super(val1, val2);
+    }
+
+    public void appendTo(Select sel, ExpContext ctx, BinaryOpExpState bstate, 
+        SQLBuffer buf, boolean val1Null, boolean val2Null) {
+        if (val1Null && val2Null)
+            buf.append("1 = 1");
+        else if (val1Null || val2Null) {
+            Val val = (val1Null) ? getValue2() : getValue1();
+            ExpState state = (val1Null) ? bstate.state2 : bstate.state1;
+            if (!isDirectComparison()) {
+                int len = val.length(sel, ctx, state);
+                for (int i = 0; i < len; i++) {
+                    if (i > 0)
+                        buf.append(" AND ");
+                    val.appendTo(sel, ctx, state, buf, i);
+                    buf.append(" IS ").appendValue(null);
+                }
+            } else
+                val.appendIsNull(sel, ctx, state, buf);
+        } else {
+            Val val1 = getValue1();
+            Val val2 = getValue2();
+            if (val1.length(sel, ctx, bstate.state1) == 1 
+                && val2.length(sel, ctx, bstate.state2) == 1) {
+                String op = "=";
+                if (sel.getTablePerClassMeta() != null) {
+                    if (val1 instanceof Type) {
+                        if ((ClassMapping) val2.getMetaData() != sel.getTablePerClassMeta())
+                            op = "<>";
+                    }
+                    else {
+                        if ((ClassMapping) val1.getMetaData() != sel.getTablePerClassMeta())
+                            op = "<>";
+                    }
+                }
+                ctx.store.getDBDictionary().comparison(buf, op,
+                    new FilterValueImpl(sel, ctx, bstate.state1, val1),
+                    new FilterValueImpl(sel, ctx, bstate.state2, val2));
+            } else {
+                int len = java.lang.Math.min(val1.length(sel, ctx, 
+                    bstate.state1), val2.length(sel, ctx, bstate.state2));
+                for (int i = 0; i < len; i++) {
+                    if (i > 0)
+                        buf.append(" AND ");
+
+                    val1.appendTo(sel, ctx, bstate.state1, buf, i);
+                    buf.append(" = ");
+                    val2.appendTo(sel, ctx, bstate.state2, buf, i);
+                }
+            }
+        }
+    }
+}

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ExpContext.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ExpContext.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ExpContext.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ExpContext.java
Sat Jun 12 14:05:43 2010
@@ -20,6 +20,7 @@ package org.apache.openjpa.jdbc.kernel.e
 
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
 
 /**
  * Expression tree context.
@@ -44,6 +45,8 @@ public class ExpContext {
      */
     public JDBCFetchConfiguration fetch; 
 
+    public ClassMapping tpcMeta = null;
+
     public ExpContext() {
     }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
Sat Jun 12 14:05:43 2010
@@ -22,7 +22,8 @@ import java.io.Serializable;
 import java.util.Date;
 
 import org.apache.openjpa.jdbc.meta.ClassMapping;
-import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
+import org.apache.openjpa.jdbc.meta.Discriminator;
+import org.apache.openjpa.jdbc.meta.strats.NoneDiscriminatorStrategy;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.jdbc.sql.Raw;
 import org.apache.openjpa.kernel.exps.AggregateListener;
@@ -87,10 +88,52 @@ public class JDBCExpressionFactory
             return contains(v1, v2);
         if (v2 instanceof PCPath && ((PCPath) v2).isUnaccessedVariable())
             return contains(v2, v1);
+        if (v1 instanceof Type || v2 instanceof Type) {
+            Value val = v1 instanceof Type ? v1 : v2;
+            verifyTypeOperation(val, null, false);
+            return new EqualTypeExpression((Val) v1, (Val) v2);
+        }
         return new EqualExpression((Val) v1, (Val) v2);
     }
 
+    private void verifyTypeOperation(Value val, Value param, boolean isNotEqual) {
+        if (val.getPath() == null)
+            return;
+        PCPath path = (PCPath) val.getPath();
+        Discriminator disc = ((Type) val).getDiscriminator();
+        if (disc == null || !(val.getMetaData().getPCSuperclass() != null ||
+            val.getMetaData().getPCSubclasses().length > 0))
+            throw new UserException(_loc.
+                get("invalid-type-argument", path.last() != null ? path.getPCPathString()
: path.getSchemaAlias()));
+        
+        if (disc.getColumns().length == 0) {
+            if (disc.getStrategy() instanceof NoneDiscriminatorStrategy) {
+                // limited support for table per class inheritance hierarchy
+                if (path.last() != null)
+                    throw new UserException(_loc.
+                        get("type-argument-unsupported", path.last().getName())); 
+                if (isNotEqual) {
+                    if (param != null && param instanceof Null)
+                        throw new UserException(_loc.
+                            get("type-in-expression-unsupported", path.getSchemaAlias()));
+                    else
+                        throw new UserException(_loc.
+                            get("type-not-equal-unsupported", path.getSchemaAlias()));
+                }
+            }
+            if (param != null && param instanceof CollectionParam)
+                throw new UserException(_loc.
+                    get("collection-param-unsupported")); 
+        }
+    }
+
     public Expression notEqual(Value v1, Value v2) {
+        if (v1 instanceof Type || v2 instanceof Type) {
+            Value val = v1 instanceof Type ? v1 : v2;
+            Value param = val == v1 ? (v2 instanceof Null ? v2 : null) : (v1 instanceof Null
? v1 : null);
+            verifyTypeOperation(val, param, true);
+            return new NotEqualTypeExpression((Val) v1, (Val) v2);
+        }
         return new NotEqualExpression((Val) v1, (Val) v2);
     }
 
@@ -123,8 +166,16 @@ public class JDBCExpressionFactory
     }
 
     public Expression contains(Value map, Value arg) {
-        if (map instanceof Const)
+        if (map instanceof Const) {
+            if (arg instanceof Type) {
+                // limited support for table per class inheritance
+                verifyTypeOperation(arg, map, false);
+                if (((ClassMapping) arg.getMetaData()).getDiscriminator().getColumns().length
== 0)
+                    return new EqualTypeExpression((Val) arg, (Val) map);
+            }
+
             return new InExpression((Val) arg, (Const) map);
+        }
         if (map instanceof SubQ)
             return new InSubQExpression((Val) arg, (SubQ) map);
         return new ContainsExpression((Val) map, (Val) arg);

Added: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualTypeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualTypeExpression.java?rev=954007&view=auto
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualTypeExpression.java
(added)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualTypeExpression.java
Sat Jun 12 14:05:43 2010
@@ -0,0 +1,87 @@
+/*
+ * 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.jdbc.kernel.exps;
+
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+
+/**
+ * Compares two entity types.
+ *
+ * @author Catalina Wei
+ */
+class NotEqualTypeExpression
+    extends CompareEqualExpression {
+
+    /**
+     * Constructor. Supply values to compare.
+     */
+    public NotEqualTypeExpression(Val val1, Val val2) {
+        super(val1, val2);
+    }
+
+    public void appendTo(Select sel, ExpContext ctx, BinaryOpExpState bstate, 
+        SQLBuffer buf, boolean val1Null, boolean val2Null) {
+        if (val1Null && val2Null)
+            buf.append("1 <> 1");
+        else if (val1Null || val2Null) {
+            Val val = (val1Null) ? getValue2() : getValue1();
+            ExpState state = (val1Null) ? bstate.state2 : bstate.state1;
+            if (!isDirectComparison()) {
+                int len = val.length(sel, ctx, state);
+                for (int i = 0; i < len; i++) {
+                    if (i > 0)
+                        buf.append(" AND ");
+                    val.appendTo(sel, ctx, state, buf, i);
+                    buf.append(" IS NOT ").appendValue(null);
+                }
+            } else
+                val.appendIsNotNull(sel, ctx, state, buf);
+        } else {
+            Val val1 = getValue1();
+            Val val2 = getValue2();
+            if (val1.length(sel, ctx, bstate.state1) == 1 
+                && val2.length(sel, ctx, bstate.state2) == 1) {
+                String op = "<>";
+                if (val1 instanceof Type)
+                    if ((ClassMapping) val2.getMetaData() != sel.getTablePerClassMeta())
+                        op = "=";
+                else
+                    if ((ClassMapping) val1.getMetaData() != sel.getTablePerClassMeta())
+                        op = "=";
+                ctx.store.getDBDictionary().comparison(buf, op,
+                    new FilterValueImpl(sel, ctx, bstate.state1, val1),
+                    new FilterValueImpl(sel, ctx, bstate.state2, val2));
+            } else {
+                int len = java.lang.Math.max(val1.length(sel, ctx, 
+                    bstate.state1), val2.length(sel, ctx, bstate.state2));
+                buf.append("(");
+                for (int i = 0; i < len; i++) {
+                    if (i > 0)
+                        buf.append(" OR ");
+                    val1.appendTo(sel, ctx, bstate.state1, buf, i);
+                    buf.append(" <> ");
+                    val2.appendTo(sel, ctx, bstate.state2, buf, i);
+                }
+                buf.append(")");
+            }
+        }
+    }
+}

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
Sat Jun 12 14:05:43 2010
@@ -1049,7 +1049,7 @@ public class PCPath
         else
             cols = getColumns(state);
 
-        if (cols == null) {
+        if (cols == null || cols.length == 0) {
             sql.append("1");
             return;
         }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Param.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Param.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Param.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Param.java
Sat Jun 12 14:05:43 2010
@@ -119,8 +119,7 @@ public class Param
                     getMappingRepositoryInstance().getMapping((Class) val,
                         ctx.store.getContext().getClassLoader(), true);
                 pstate.disc = pstate.mapping.getDiscriminator();
-                pstate.discValue = pstate.disc != null ? pstate.disc.getValue()
-                    : null;
+                pstate.discValue = pstate.disc.getValue() != null ? pstate.disc.getValue()
: "1";
             }
         } else if (ImplHelper.isManageable(val)) {
             ClassMapping mapping = ctx.store.getConfiguration().

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
Sat Jun 12 14:05:43 2010
@@ -85,6 +85,7 @@ public class SelectConstructor
         // create a new select and initialize it with the joins needed for
         // the criteria of this query
         sel = newSelect(ctx, parent, alias, exps, state);
+        sel.setTablePerClassMeta(ctx.tpcMeta);
 
         // create where clause; if there are no where conditions and
         // no ordering or projections, we return null to signify that this

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Type.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Type.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Type.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Type.java
Sat Jun 12 14:05:43 2010
@@ -25,6 +25,7 @@ import org.apache.openjpa.jdbc.meta.Disc
 import org.apache.openjpa.jdbc.sql.Result;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
+import org.apache.openjpa.kernel.exps.Path;
 import org.apache.openjpa.util.InternalException;
 
 /**
@@ -94,4 +95,12 @@ class Type
         // since we override appendTo(), this method should never be called
         throw new InternalException();
     }
+
+    public Path getPath() {
+        return getValue() instanceof Path ? (Path) getValue() : null;
+    }
+
+    public Discriminator getDiscriminator() {
+        return _disc;
+    }
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
Sat Jun 12 14:05:43 2010
@@ -905,6 +905,12 @@ public class LogicalUnion
         public void logEagerRelations() {
             sel.logEagerRelations();            
         }
+        public void setTablePerClassMeta(ClassMapping meta) {            
+        }
+
+        public ClassMapping getTablePerClassMeta() {
+            return sel.getTablePerClassMeta();
+        }
     }
 
     /**

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java Sat Jun
12 14:05:43 2010
@@ -737,4 +737,14 @@ public interface Select
      * Extended trace that logs eager relations
      */
     public void logEagerRelations();
+
+    /**
+     * Set table-per-class metadata for polymorphic queries
+     */
+    public void setTablePerClassMeta(ClassMapping meta);
+
+    /**
+     * get table-per-class metadata for polymorphic queries
+     */
+    public ClassMapping getTablePerClassMeta();
 }

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=954007&r1=954006&r2=954007&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 Sat
Jun 12 14:05:43 2010
@@ -169,6 +169,13 @@ public class SelectImpl
 
     // A path navigation is begin with this schema alias
     private String _schemaAlias = null;
+    private ClassMapping _tpcMeta = null;
+    public ClassMapping getTablePerClassMeta() {
+        return _tpcMeta;
+    }
+    public void setTablePerClassMeta(ClassMapping meta) {
+        _tpcMeta = meta;
+    }
      
     /**
      * Helper method to return the proper table alias for the given alias index.

Modified: openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/exps/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/exps/localizer.properties?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/exps/localizer.properties
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/exps/localizer.properties
Sat Jun 12 14:05:43 2010
@@ -34,4 +34,19 @@ empty-collection-parm: Input parameter "
 count-distinct-multi-col-only: Count distinct compound primary key is not \
     supported when there are other projection items.
 count-distinct-multi-col-subselect-unsupported: Count distinct multiple columns \
-	in the subselect is not supported.
\ No newline at end of file
+	in the subselect is not supported.
+invalid-type-argument: The argument "{0}" in type discriminator is not involved in any \
+    inheritance class hierarchy. Nonpolymorphic type comparison is not supported.
+type-argument-unsupported: A single valued object path "{0}" for the TYPE argument in \
+    a table per class inheritance hierarchy is not supported.
+type-not-equal-unsupported: The argument "{0}" in type discriminator is in a table per class
\
+    or mapped super class inheritance hierarchy. The not equal type comparison for such entity
\
+    is not supported. Rewrite the query in type equal comparison  \
+    and or operators for polymorphic query results.
+type-in-expression-unsupported: The argument "{0}" in type discriminator is in a table per
class \
+    inheritance hierarchy. The type discriminator in IN expression for such entity \
+    is not supported. Rewrite the query in type equal comparison  \
+    and or operators for polymorphic query results.
+collection-param-unsupported: The collection parameter used in IN expression is not supported
\
+    for table per class inheritance hierarchy or inheritance type joined strategy. \
+    Use type equal comparison and or operators for polymorphic query results.

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestDefaultInheritanceStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestDefaultInheritanceStrategy.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestDefaultInheritanceStrategy.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestDefaultInheritanceStrategy.java
Sat Jun 12 14:05:43 2010
@@ -120,6 +120,15 @@ public class TestDefaultInheritanceStrat
         em.persist(b);
         em.getTransaction().commit();
 
+        // test entity type discriminator queries for polymorphic results
+        em.clear();
+        String query = "select a from BaseClass a where TYPE(a) = BaseClass";
+        List rs = em.createQuery(query).getResultList();
+        assertTrue(rs.get(0) instanceof BaseClass);
+        query = "select a from BaseClass a where TYPE(a) = SubclassA";
+        rs = em.createQuery(query).getResultList();
+        assertTrue(rs.get(0) instanceof SubclassA);
+
         em.clear();
         
         verifyDtypeColumnEntriesAndMapping(em, "BaseClass", 4, BaseClass.class);
@@ -132,7 +141,7 @@ public class TestDefaultInheritanceStrat
 
         verifyInheritanceQueryResult(em, "BaseClass", 
             classArray(BaseClass.class), 0, 1, 2, 3);
-        
+
         em.close();
     }
 
@@ -207,7 +216,24 @@ public class TestDefaultInheritanceStrat
         em.persist(mc);
         em.persist(b2);
         em.getTransaction().commit();
-        
+
+        // test entity type discriminator queries for polymorphic results
+        em.clear();
+        String query = "select a from BaseClass2 a where TYPE(a) = MidClass";
+        List rs = em.createQuery(query).getResultList();
+        for (int i = 0; i < rs.size(); i++)
+        assertTrue(rs.get(i) instanceof MidClass);
+
+        query = "select a from BaseClass2 a where TYPE(a) = SubclassE";
+        rs = em.createQuery(query).getResultList();
+        for (int i = 0; i < rs.size(); i++)
+            assertTrue(rs.get(i) instanceof SubclassE);   
+
+        query = "select a from BaseClass2 a where TYPE(a) = BaseClass2";
+        rs = em.createQuery(query).getResultList();
+        for (int i = 0; i < rs.size(); i++)
+            assertTrue(rs.get(i) instanceof BaseClass2);
+
         em.clear();
 
         // Verify that baseclass2 contains a discriminator column

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestFindAbstractClass.java
Sat Jun 12 14:05:43 2010
@@ -18,7 +18,10 @@
  */
 package org.apache.openjpa.persistence.inheritance;
 
+import java.util.List;
+
 import javax.persistence.EntityManager;
+import javax.persistence.InheritanceType;
 
 import junit.textui.TestRunner;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
@@ -33,7 +36,7 @@ public class TestFindAbstractClass
     extends SingleEMFTestCase {
 
     public void setUp() {
-        setUp(AbstractBase.class, ConcreteSubclass.class);
+        setUp(AbstractBase.class, ConcreteSubclass.class, CLEAR_TABLES);
 
         ConcreteSubclass e = new ConcreteSubclass();
         e.setId("id");
@@ -46,6 +49,16 @@ public class TestFindAbstractClass
         em.close();
     }
 
+    public void testEntityTypeInheritanceTypeJoined() {
+        EntityManager em = emf.createEntityManager();
+        String query = "select c from AbstractBase c where TYPE(c) = ConcreteSubclass";
+        List rs = em.createQuery(query).getResultList();
+        assertTrue(rs.get(0) instanceof ConcreteSubclass);
+        query = "select c from AbstractBase c";
+        rs = em.createQuery(query).getResultList();
+        assertTrue(rs.get(0) instanceof ConcreteSubclass);
+    }
+
     public void testFind() {
         EntityManager em = emf.createEntityManager();
         AbstractBase e = em.find(AbstractBase.class, "id");

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java
Sat Jun 12 14:05:43 2010
@@ -20,6 +20,8 @@ package org.apache.openjpa.persistence.i
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
+
 import javax.persistence.EntityManager;
 
 import junit.textui.TestRunner;
@@ -52,6 +54,20 @@ public class TestAbstractJoinedAppId
         em.close();
     }
 
+    public void testEntityTypeForAbstractJoined() {
+        EntityManager em = emf.createEntityManager();
+        String query = "select s from RelationOwner r join r.supers s where TYPE(s) = Subclass";
+        List rs = em.createQuery(query).getResultList();
+        assertTrue(rs.size() > 0);
+        for (int i = 0; i < rs.size(); i++)
+            assertTrue(rs.get(i) instanceof Subclass);
+        query = "select s from Superclass s where TYPE(s) = Subclass";
+        rs = em.createQuery(query).getResultList();
+        assertTrue(rs.size() > 0);
+        for (int i = 0; i < rs.size(); i++)
+            assertTrue(rs.get(i) instanceof Subclass);
+    }
+
     public void testTraverseRelation() {
         EntityManager em = emf.createEntityManager();
         RelationOwner ro = em.find(RelationOwner.class, 1);

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/TestInheritanceTypeJoinedQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/TestInheritanceTypeJoinedQuery.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/TestInheritanceTypeJoinedQuery.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/jointable/TestInheritanceTypeJoinedQuery.java
Sat Jun 12 14:05:43 2010
@@ -18,11 +18,14 @@
  */
 package org.apache.openjpa.persistence.inheritance.jointable;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
+import org.apache.openjpa.persistence.ArgumentException;
 import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
 
@@ -50,6 +53,37 @@ public class TestInheritanceTypeJoinedQu
         em.close();
     }
 
+    public void testInheritanceJoinedTypeOperator() {
+        EntityManager em = emf.createEntityManager();
+        Query q = null;
+        String qS = null;
+        qS = "SELECT p FROM Person p where TYPE(p) = Contractor";
+        q = em.createQuery(qS); 
+        List rs = q.getResultList();
+        assertEquals(3, rs.size());
+        for (int i = 0; i < rs.size(); i++)
+            assertTrue(rs.get(i) instanceof Contractor);
+        qS = "select p from Person p where TYPE(p) in (?1) order by p.name";
+        q = em.createQuery(qS).setParameter(1, Contractor.class);
+        rs = q.getResultList();
+        assertEquals(3, rs.size());
+        for (int i = 0; i < rs.size(); i++)
+            assertTrue(rs.get(i) instanceof Contractor);
+
+        qS = "select p from Person p where TYPE(p) in ?1 order by p.name";
+        Collection<Class<?>> params = new ArrayList<Class<?>>(2);
+        params.add(Contractor.class);
+        params.add(Employee.class);
+        try {
+            q = em.createQuery(qS).setParameter(1, params);
+            rs = q.getResultList();
+        } catch (ArgumentException e) {
+            // as expected
+            //System.out.println(e.getMessage());
+        }
+        
+    }
+
     public void testInheritanceTypeJoinedQuery() {
         EntityManager em = emf.createEntityManager();
         Query q = null;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/mappedsuperclass/TestMappedSuperClass.java
Sat Jun 12 14:05:43 2010
@@ -18,8 +18,11 @@
  */
 package org.apache.openjpa.persistence.inheritance.mappedsuperclass;
 
+import java.util.List;
+
 import javax.persistence.EntityManager;
 
+import org.apache.openjpa.persistence.ArgumentException;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
@@ -34,16 +37,38 @@ public class TestMappedSuperClass extend
 
     public void setUp() {
         setUp(CashBaseEntity.class, 
-              SituationDA.class, ValuableItemDA.class);
+              SituationDA.class, ValuableItemDA.class, CLEAR_TABLES);
     }
 
     public void testMappedSuperClass() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        SituationDA s = new SituationDA();
-        s.setCashBoxPeriodSerial("test");
-        s.setType((short)1);
-        em.persist(s);
+        for (int i = 0; i < 3; i++) {
+            SituationDA s = new SituationDA();
+            s.setCashBoxPeriodSerial("test");
+            s.setType((short) (i+1));
+            em.persist(s);
+        }
+        for (int i = 0; i < 3; i++) {
+            ValuableItemDA v = new ValuableItemDA();
+            v.setCode((short)(10+i));
+            em.persist(v);
+        }
         em.getTransaction().commit();
+        
+        em.clear();
+
+        // test polymorphic queries
+        String query = "select s from CashBaseEntity s where TYPE(s) = SituationDA";
+        List rs = em.createQuery(query).getResultList();
+        for (int i = 0; i < rs.size(); i++)
+            assertTrue(rs.get(i) instanceof SituationDA);
+        
+        query = "select s from CashBaseEntity s where TYPE(s) <> ValuableItemDA";
+        try {
+            rs = em.createQuery(query).getResultList();
+        } catch (ArgumentException e) {
+            // as expected
+        }
     }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java
Sat Jun 12 14:05:43 2010
@@ -18,8 +18,11 @@
  */
 package org.apache.openjpa.persistence.inheritance.polymorphic;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
+import org.apache.openjpa.persistence.ArgumentException;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
@@ -60,51 +63,56 @@ public class TestTablePerClassInheritanc
         		EnglishParagraph.class, FrenchParagraph.class, 
         		GermanParagraph.class, Translatable.class);
     }
-    
+
+    public void populate() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        /**
+         * Aggregate query operations can not be performed on unjoined 
+         * subclasses. Hence all concrete subclasses of abstract base
+         * class is counted separately to count all Translatable instances.
+         */
+        
+        EnglishParagraph english = new EnglishParagraph();
+        FrenchParagraph french   = new FrenchParagraph();
+        GermanParagraph german   = new GermanParagraph();
+        
+        Translation translation1 = new Translation(); 
+        Translation translation2 = new Translation(); 
+        Translation translation3 = new Translation(); 
+        Translation translation4 = new Translation(); 
+        
+        english.setContent("Hello");
+        french.setContent("Bon jour");
+        german.setContent("Guten Tag");
+
+        
+        translation1.setTranslatable(english);
+        translation2.setTranslatable(english);
+        translation3.setTranslatable(french);
+        translation4.setTranslatable(german);
+        
+        english.addTranslation(translation1);
+        english.addTranslation(translation2);
+        french.addTranslation(translation3);
+        german.addTranslation(translation4);
+        
+        em.persist(translation1);
+        em.persist(translation2);
+        em.persist(translation3);
+        em.persist(translation4);
+        em.getTransaction().commit();
+        em.close();
+    }
+
 	@SuppressWarnings("unchecked")
     public void testConsistency() {
-		OpenJPAEntityManager em = emf.createEntityManager();
-		em.getTransaction().begin();
-		/**
-		 * Aggregate query operations can not be performed on unjoined 
-		 * subclasses. Hence all concrete subclasses of abstract base
-         * class is counted separately to count all Translatable instances.
-		 */
-		int nTranslatableBefore = count(UNJOINED_SUBCLASSES);
-		int nTranslationBefore = count(Translation.class);
-		
-		EnglishParagraph english = new EnglishParagraph();
-		FrenchParagraph french   = new FrenchParagraph();
-		GermanParagraph german   = new GermanParagraph();
-		
-		Translation translation1 = new Translation(); 
-		Translation translation2 = new Translation(); 
-		Translation translation3 = new Translation(); 
-		Translation translation4 = new Translation(); 
-		
-		english.setContent("Hello");
-		french.setContent("Bon jour");
-		german.setContent("Guten Tag");
+        OpenJPAEntityManager em = emf.createEntityManager();
 
-		
-		translation1.setTranslatable(english);
-		translation2.setTranslatable(english);
-		translation3.setTranslatable(french);
-		translation4.setTranslatable(german);
-		
-		english.addTranslation(translation1);
-		english.addTranslation(translation2);
-		french.addTranslation(translation3);
-		german.addTranslation(translation4);
-		
-		em.persist(translation1);
-		em.persist(translation2);
-		em.persist(translation3);
-		em.persist(translation4);
-		em.getTransaction().commit();
-		
-		em.clear();
+        int nTranslatableBefore = count(UNJOINED_SUBCLASSES);
+        int nTranslationBefore = count(Translation.class);
 
+        populate();
 		int nTranslatableAfter = count(UNJOINED_SUBCLASSES);
 		int nTranslationAfter  = count(Translation.class);
 		
@@ -152,5 +160,61 @@ public class TestTablePerClassInheritanc
 		}
 		return total;
 	}
-	
+
+    public void testEntityTypeForTablePerClassInheritance() {
+        populate();
+        OpenJPAEntityManager em = emf.createEntityManager();
+        String query = "select tr from Translatable tr join tr.translations t where " +
+                "TYPE(tr) = EnglishParagraph";
+        List rs = em.createQuery(query).getResultList();
+        assertEquals(2, rs.size());
+        for (int i=0; i < rs.size(); i++)
+            assertTrue(rs.get(i) instanceof EnglishParagraph);
+        
+        query = "select distinct tr from Translatable tr join tr.translations t where " +
+            "TYPE(tr) = EnglishParagraph or TYPE(tr) = FrenchParagraph";
+        rs = em.createQuery(query).getResultList();
+        assertEquals(2, rs.size());
+        for (int i=0; i < rs.size(); i++)
+            assertTrue(!(rs.get(i) instanceof GermanParagraph));
+        
+        query = "select distinct tr from Translatable tr join tr.translations t where " +
+            "TYPE(tr) in (?1, ?2)";
+        try {
+            rs = em.createQuery(query).setParameter(1, EnglishParagraph.class).
+            setParameter(2, FrenchParagraph.class).getResultList();
+        } catch(ArgumentException e) {
+            // as expected
+            //System.out.println(e.getMessage());
+        }
+        
+        query = "select tr from Translatable tr join tr.translations t where " +
+            "TYPE(tr) <> EnglishParagraph";
+        try {
+            rs = em.createQuery(query).getResultList();
+        } catch(ArgumentException e) {
+            // as expected
+            //System.out.println(e.getMessage());
+        }
+
+        String query1 = "select t from Translation t where TYPE(t.translatable) = EnglishParagraph";
+        try {
+            rs = em.createQuery(query1).getResultList();
+        } catch(ArgumentException e) {
+            // as expected
+            //System.out.println(e.getMessage());
+        }
+
+        query1 = "select tr from Translatable tr join tr.translations t where " +
+                "TYPE(tr) in ?1";
+        Collection<Class <?>> params = new ArrayList(2);
+        params.add(EnglishParagraph.class);
+        params.add(FrenchParagraph.class);
+        try {
+            rs = em.createQuery(query).setParameter(1, params).getResultList();
+        } catch(ArgumentException e) {
+            // as expected
+            //System.out.println("e.getMessages()");
+        }
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java?rev=954007&r1=954006&r2=954007&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java
Sat Jun 12 14:05:43 2010
@@ -71,6 +71,19 @@ public class TestEntityTypeExpression ex
         endEm(em);
     }
 
+    public void testTypeOnNonPolymorphicEntity() {
+        EntityManager em = currentEntityManager();
+        String query = "select a from Address a where type(a) = ?1";
+        List rs = null;
+        try {
+            rs =  em.createQuery(query).setParameter(1, Address.class).getResultList();
+            System.out.println("rs size="+rs.size());
+        } catch(Exception e) {
+            // as expected
+            //System.out.println(e.getMessage());
+        }
+    }
+
     @SuppressWarnings("unchecked")
     public void testTypeExpression() {
         EntityManager em = currentEntityManager();



Mime
View raw message