mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 15:55:55 +00:00
#710 - Behavior change - query with invalid fetch path (without properties) now throws PersistenceException
This commit is contained in:
@@ -1654,7 +1654,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user