/* * (non-Javadoc) * @see org.springframework.data.repository.CrudRepository#save(java.lang.Object) */ @Transactional public <S extends T> S save(S entity) { if (entityInformation.isNew(entity)) { em.persist(entity); return entity; } else { return em.merge(entity); } }
Before save, judge whether the primary key is empty. If it is empty, add it, and if it is not empty, modify it.
but. . . One exception. . .
Adding @version will not work, because the update needs to be judged according to the version