Bugfix/create entity bean unload (#1729)

* #1726 Add a testcase to reveal wrong behaviour of createEntityBean

* #1726 FIX: createEntityBean must not unload properties for "new" beans

(cherry picked from commit 270721bdb54373a83ef00b19a3c35da50f2a2bf5)
This commit is contained in:
jonasPoehler
2019-06-10 16:09:12 +12:00
committed by Rob Bygrave
parent 385cc76e34
commit 2923dd1d96
3 changed files with 91 additions and 6 deletions
@@ -1915,18 +1915,19 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
beanPostConstructListener.autowire(bean); // calls all registered listeners
beanPostConstructListener.postConstruct(bean); // calls first the @PostConstruct method and then the listeners
}
if (unloadProperties.length > 0) {
if (isNew) {
if (beanPostConstructListener != null) {
beanPostConstructListener.postCreate(bean);
// if bean is not new, postLoad will be executed later in the bean's lifecycle
}
// do not unload properties for new beans!
} else if (unloadProperties.length > 0) {
// 'unload' any properties initialised in the default constructor
EntityBeanIntercept ebi = bean._ebean_getIntercept();
for (int unloadProperty : unloadProperties) {
ebi.setPropertyUnloaded(unloadProperty);
}
}
if (beanPostConstructListener != null && isNew) {
beanPostConstructListener.postCreate(bean);
// if bean is not new, postLoad will be executed later in the bean's lifecycle
}
return bean;
} catch (Exception ex) {