@Override
@SuppressWarnings("unchecked")
public void onPostSave(E entity,JpaSupportRepository<E, ID> persistentContext,Serializable id) {
Class<?> entityClass = ReflectionUtils.getTargetClass(entity);
TreeEntity treeEntity = ReflectionUtils.getAnnotation(entityClass,TreeEntity.class);
if (treeEntity != null) {
//from {0} tree where tree.{1} = {2} and (select count(c) from {0} c where c.{3}.{4} = r.{4}) = {5}
String hql = MessageFormat.format(treeEntity.refreshHql(),
persistentContext.getEntityName(),
treeEntity.leafProperty(),
treeEntity.leafValue(),
treeEntity.parentProperty(),
persistentContext.getIdName(),
treeEntity.unleafValue());
List<E> list = persistentContext.getEntityManager().createQuery(hql).getResultList();
for (E e : list) {
Object value = ConvertUtils.convertToObject(treeEntity.unleafValue(), treeEntity.leafClass());
ReflectionUtils.invokeSetterMethod(e,treeEntity.leafProperty(), value);
persistentContext.save(e);
}
}
}