mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1516 - More user friendly exceptions - BeanNotEnhancedException, BeanNotRegisteredException
This commit is contained in:
@@ -2,10 +2,12 @@ package io.ebean;
|
||||
|
||||
import io.ebean.annotation.TxIsolation;
|
||||
import io.ebean.cache.ServerCacheManager;
|
||||
import io.ebean.config.BeanNotEnhancedException;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.plugin.Property;
|
||||
import io.ebean.text.csv.CsvReader;
|
||||
import io.ebean.text.json.JsonContext;
|
||||
import io.ebean.datasource.DataSourceConfigurationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -160,6 +162,15 @@ public final class Ebean {
|
||||
defaultServer = getWithCreate(defaultName.trim());
|
||||
}
|
||||
}
|
||||
} catch (BeanNotEnhancedException e) {
|
||||
throw e;
|
||||
|
||||
} catch (DataSourceConfigurationException e) {
|
||||
String msg = "Configuration error creating DataSource for the default EbeanServer." +
|
||||
" This typically means a missing application-test.yml or missing ebean-test-config dependency." +
|
||||
" See https://ebean-orm.github.io/docs/trouble-shooting#datasource";
|
||||
throw new DataSourceConfigurationException(msg, e);
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error trying to create the default EbeanServer", e);
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package io.ebean.config;
|
||||
|
||||
/**
|
||||
* Throw when an processing an entity bean that is not bytecode enhanced.
|
||||
*
|
||||
* Refer: https://ebean-orm.github.io/docs/trouble-shooting#not-enhanced
|
||||
*/
|
||||
public class BeanNotEnhancedException extends IllegalStateException {
|
||||
|
||||
public BeanNotEnhancedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package io.ebean.config;
|
||||
|
||||
/**
|
||||
* Throw when an processing thinks a bean is not registered.
|
||||
*
|
||||
* Refer: https://ebean-orm.github.io/docs/trouble-shooting#not-registered
|
||||
*/
|
||||
public class BeanNotRegisteredException extends IllegalStateException {
|
||||
|
||||
public BeanNotRegisteredException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import io.ebean.RawSqlBuilder;
|
||||
import io.ebean.annotation.ConstraintMode;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.config.BeanNotEnhancedException;
|
||||
import io.ebean.config.EncryptKey;
|
||||
import io.ebean.config.EncryptKeyManager;
|
||||
import io.ebean.config.NamingConvention;
|
||||
@@ -388,6 +389,9 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
return asOfTableMap;
|
||||
|
||||
} catch (BeanNotEnhancedException e) {
|
||||
throw e;
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
logger.error("Error in deployment", e);
|
||||
throw e;
|
||||
@@ -1471,7 +1475,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
if (isPersistentField(prop)) {
|
||||
throw new IllegalStateException(
|
||||
"If you are running in an IDE with enhancement plugin try a Build -> Rebuild Project to recompile and enhance all entity beans. " +
|
||||
"Error - property " + propName + " not found in " + reflectProps + " for type " + desc.getBeanType());
|
||||
"Error - property " + propName + " not found in " + reflectProps + " for type " + desc.getBeanType());
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -1554,7 +1558,9 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
Class<?> beanClass = desc.getBeanType();
|
||||
|
||||
if (!hasEntityBeanInterface(beanClass)) {
|
||||
throw new IllegalStateException("Bean " + beanClass + " is not enhanced?");
|
||||
String msg = "Bean " + beanClass + " is not enhanced? If you are running in IDEA or Eclipse check" +
|
||||
" that the enhancement plugin is installed. See https://ebean-orm.github.io/docs/trouble-shooting#not-enhanced";
|
||||
throw new BeanNotEnhancedException(msg);
|
||||
}
|
||||
|
||||
// the bean already implements EntityBean
|
||||
@@ -1583,7 +1589,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
// ok to stop and treat just the same as Object.class
|
||||
return;
|
||||
}
|
||||
throw new IllegalStateException("Super type " + superclass + " is not enhanced?");
|
||||
throw new BeanNotEnhancedException("Super type " + superclass + " is not enhanced? See https://ebean-orm.github.io/docs/trouble-shooting#not-enhanced");
|
||||
}
|
||||
|
||||
// recursively continue up the inheritance hierarchy
|
||||
@@ -1666,11 +1672,14 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
private ElementHelp elementHelper(ManyType manyType) {
|
||||
switch (manyType) {
|
||||
case LIST: return new ElementHelpList();
|
||||
case SET: return new ElementHelpSet();
|
||||
case MAP: return new ElementHelpMap();
|
||||
case LIST:
|
||||
return new ElementHelpList();
|
||||
case SET:
|
||||
return new ElementHelpSet();
|
||||
case MAP:
|
||||
return new ElementHelpMap();
|
||||
default:
|
||||
throw new IllegalStateException("manyType unexpected "+manyType);
|
||||
throw new IllegalStateException("manyType unexpected " + manyType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.config.BeanNotRegisteredException;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocOne;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
@@ -22,8 +23,8 @@ public class BeanEmbeddedMetaFactory {
|
||||
BeanDescriptor<?> targetDesc = owner.getBeanDescriptor(prop.getTargetType());
|
||||
if (targetDesc == null) {
|
||||
String msg = "Could not find BeanDescriptor for " + prop.getTargetType()
|
||||
+ ". Perhaps the EmbeddedId class is not registered?";
|
||||
throw new PersistenceException(msg);
|
||||
+ ". Perhaps the EmbeddedId class is not registered? See https://ebean-orm.github.io/docs/trouble-shooting#not-registered";
|
||||
throw new BeanNotRegisteredException(msg);
|
||||
}
|
||||
|
||||
// deployment override information (column names)
|
||||
|
||||
Reference in New Issue
Block a user