Lets say I have a table called "USER". In this table, I have all the user data, and I assign the user a unique id and therefore each row is unique.
It looks something like this:
@Entity
@Table(name = "USER")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_seq")
@Column(name = "USER_ID")
private Long userId;
@Column(name = "FRST_NAME")
private String firstName;
@Column(name = "LAST_NAME")
private String lastName;
... a lot more stuff ...
}
I also have another table where I assign all the roles the user has, which each row looks like:
@Entity
@Table(name = "USER_ROLES")
public class UserRoleMap {
@Id
@Column(name = "USER_ID")
Long userId;
@Column(name = "USER_ROLE_ID")
Long userRoleId;
@Column(name = "UPDATED_DATE")
String updatedDate;
@Column(name = "UPDATED_BY")
String updatedBy;
}
This table has no explicit unique key. The data could easily look like the following, where 12278 is the unique userId.
12,278 8,420 pretend_timestamp admin_user
12,278 8,430 pretend_timestamp admin_user
12,278 8,476 pretend_timestamp admin_user
12,278 8,478 pretend_timestamp admin_user
12,278 18,578 pretend_timestamp admin_user
12,278 8,482 pretend_timestamp admin_user
12,278 18,539 pretend_timestamp admin_user
So how do I do the following using idiomatic spring-boot?
DELETE USER_ROLES where USER_ID = 12278
I have tried the following, but spring-boot throws an error:
userRoleRepository.deleteById(user.getUserId);
gives
org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update