diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java index e94fa62c7..d5c79d9e2 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java @@ -1654,7 +1654,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { return assocProp.getTargetDescriptor().getBeanDescriptor(splitBegin[1]); } else { - throw new RuntimeException("Error getting BeanDescriptor for path " + path + " from " + getFullName()); + throw new PersistenceException("Invalid path " + path + " from " + getFullName()); } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/SqlTreeAlias.java b/src/main/java/com/avaje/ebeaninternal/server/query/SqlTreeAlias.java index 483c6ca66..1fe2b1a7f 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/SqlTreeAlias.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/SqlTreeAlias.java @@ -1,18 +1,17 @@ package com.avaje.ebeaninternal.server.query; +import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; +import com.avaje.ebeaninternal.server.el.ElPropertyDeploy; + +import javax.persistence.PersistenceException; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.TreeSet; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.server.el.ElPropertyDeploy; - /** * Special Map of the logical property joins to table alias. - * - * @author rbygrave */ public class SqlTreeAlias { @@ -61,7 +60,10 @@ public class SqlTreeAlias { if (propJoins != null) { for (String propJoin : propJoins) { ElPropertyDeploy elProp = desc.getElPropertyDeploy(propJoin); - if (elProp != null && elProp.getBeanProperty().isEmbedded()) { + if (elProp == null) { + throw new PersistenceException("Invalid path " + propJoin + " from " + desc.getFullName()); + + } else if (elProp.getBeanProperty().isEmbedded()) { addEmbeddedPropertyJoin(propJoin); } else { diff --git a/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryDetail.java b/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryDetail.java index 9bb6cb081..9f0eb77ef 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryDetail.java +++ b/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryDetail.java @@ -353,7 +353,10 @@ public class OrmQueryDetail implements Serializable { for (String fetchPath : fetchPaths.keySet()) { ElPropertyDeploy elProp = beanDescriptor.getElPropertyDeploy(fetchPath); - if (elProp != null && elProp.containsManySince(manyFetchProperty)) { + if (elProp == null) { + throw new PersistenceException("Invalid fetch path " + fetchPath + " from " + beanDescriptor.getFullName()); + } + if (elProp.containsManySince(manyFetchProperty)) { // this is a join to a *ToMany OrmQueryProperties chunk = fetchPaths.get(fetchPath); diff --git a/src/test/java/com/avaje/tests/query/TestInvalidFetchPath.java b/src/test/java/com/avaje/tests/query/TestInvalidFetchPath.java index 16ca0314c..2299eeae0 100644 --- a/src/test/java/com/avaje/tests/query/TestInvalidFetchPath.java +++ b/src/test/java/com/avaje/tests/query/TestInvalidFetchPath.java @@ -5,15 +5,31 @@ import com.avaje.ebean.Ebean; import com.avaje.tests.model.basic.Customer; import org.junit.Test; +import javax.persistence.PersistenceException; + public class TestInvalidFetchPath extends BaseTestCase { - @Test - public void testWithPathAndProperties() { + @Test(expected = PersistenceException.class) + public void invalidFetchPathAndProperties_expect_error() { Ebean.find(Customer.class) - .fetch("notHaveProps", "notHaveProps") + .fetch("notValidPath", "notHaveProps") .findList(); - } + @Test(expected = PersistenceException.class) + public void invalidFetchPath_expect_error() { + + Ebean.find(Customer.class) + .fetch("notValidPath") + .findList(); + } + + @Test + public void fetchWithInvalidPropertyName_expect_allowed() { + + Ebean.find(Customer.class) + .fetch("billingAddress", "invalidPropertyName") + .findList(); + } }