From 9ece24ade3a94b1227bfd40ae9b37b9def386291 Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Fri, 29 Feb 2008 19:16:27 +0000 Subject: [PATCH] Better error message. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@632412 13f79535-47bb-0310-9956-ffa450edef68 --- .../kernel/jpql/JPQLExpressionBuilder.java | 4 +- .../openjpa/kernel/jpql/localizer.properties | 3 ++ ...TestJPQLWithoutIdentificationVariable.java | 40 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJPQLWithoutIdentificationVariable.java diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java index 9169395b8..40394b0ea 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java @@ -1355,8 +1355,8 @@ public class JPQLExpressionBuilder else if (val.getMetaData() != null) path = newPath(val, val.getMetaData()); else - throw parseException(EX_USER, "path-no-meta", - new Object[]{ assemble(node), null }, null); + throw parseException(EX_USER, "path-invalid", + new Object[]{ assemble(node), name }, null); // walk through the children and assemble the path boolean allowNull = !inner; diff --git a/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties b/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties index 475f5e261..f1da81f10 100644 --- a/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties +++ b/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties @@ -45,6 +45,9 @@ unknown-type: Cannot determine the type of field "{0}". unexpected-var: The variable "{0}" was found where a constant or \ field value was expected. path-no-meta: Attempt to query field "{0}" from non-entity class "{1}". +path-invalid: Attempt to query field "{0}" from non-entity variable "{1}". \ + Perhaps you forgot to prefix the path in question with an identification \ + variable from your FROM clause? not-yet-supported: Expressions of type "{0}" are not yet supported. bad-positional-parameter: The positional parameter "{0}" is invalid. \ Positional parameters must be integers greater than zero. diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJPQLWithoutIdentificationVariable.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJPQLWithoutIdentificationVariable.java new file mode 100644 index 000000000..ff3f3064b --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJPQLWithoutIdentificationVariable.java @@ -0,0 +1,40 @@ +/* + * 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 javax.persistence.Query; + +import org.apache.openjpa.persistence.test.SingleEMTestCase; + +public class TestJPQLWithoutIdentificationVariable extends SingleEMTestCase { + + public void setUp() { + setUp(ManyOneEntity.class, ManyOneEntitySub.class); + } + + public void testJPQLWithoutIdentificationVariable() { + try { + em.createQuery("select o from ManyOneEntity o " + + "where rel.name = :name").compile(); + } catch (RuntimeException e) { + assertTrue(e.getMessage().contains( + "Perhaps you forgot to prefix the path")); + } + } +}