@Transactional @Modifying @Query("update User u set u.email=:#{#user.email} where u.id=:#{#user.id}") voiddynamicUpdateEmailById(@Param("user") User user);
@Transactional @Modifying @Query("update User u set u.email=?2 where u.id=?1") voiddynamicUpdateEmailById(int id, String email);
对于调用SimpJpaReposiory#sava插入新纪录后get不到id(主键)的问题
添加@GeneratedValue注解修改主键生成策略为GenerationType.IDENTITY,默认是GenerationType.AUTO 异常: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement 解决: 使用GenerationType.IDENTITY