JPA 多对多映射报错信息:detached entity passed to persist

报错信息:

org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: com.daqiang.auth.server.entity.SysSystem; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: com.daqiang.auth.server.entity.SysSystem

解决办法:

保存时预先设置一个任意主键:

sysRole.setRoleId((long) 0);


你可能感兴趣的:(Spring,Data,JPA)