A pit of jpa save

/*
	 * (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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326778792&siteId=291194637