public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable { StringBuffer sb = new StringBuffer(); sb.append(target.getClass().getName()).append(".").append(method.getName()); if (countMap.containsKey(sb.toString())) { Integer count = countMap.get(sb.toString()); if (method.getName().equalsIgnoreCase("save") && count.intValue() > this.batchSize) { em.flush(); //em.clear(); countMap.put(sb.toString(), new Integer(0)); } else countMap.put(sb.toString(), new Integer(count.intValue()+1)); } else countMap.put(sb.toString(), new Integer(1)); }