INNER CODE UNIT · Java
getCascadeEntity
chaokunyang/jkes · jkes-boot/jkes-spring-data-jpa/src/main/java/com/timeyang/jkes/spring/jpa/EventSupport.java:276
private Collection<Object> getCascadeEntity(Object entity, LinkedList<Object> context) {
// Use map to address JavaBean without overriding equals and hashCode() correctly. If JavaBean override equals and hashCode() correctly, use Set() is HashSet is best choice.
Map<String, Object> entityMap = new HashMap<>();
// because jpa annotation is annotated on public method when annotated on method, so there is no need to use getDeclaredMethods and loop
Method[] methods = entity.getClass().getMethods();
for(Method method : methods) {
CascadeType[] cascadeTypes = getCascadeTypes(method);
if(cascadeTypes != null) {
for(CascadeType cascadeType : cascadeTypes) {
if(cascadeType == CascadeType.ALL
|| cascadeType == CascadeType.PERSIST || cascadeType == CascadeType.MERGE) {
try {
Object o = method.invoke(entity);
if(!context.contains(o)) entityMap.put(ReflectionUtils.getFieldNameForGetter(method), o);
break;
} catch (IllegalAccessException e) {