Hello !
I have a ProfileFactory entity that contains List<ProfileRoleFactory> and I don't know how to tell to Springboot to save automatically when I add a role to a profile like:
myProfile.getRoles().addRole(roleExample);
Thank you in advance for your help
ProfileFactory.class
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Data
@Entity
@Table(name = "profiles")
public class ProfileFactory {
@Id
@Column(name = "id",
nullable = false,
columnDefinition = "CHARACTER VARYING(36)")
private String id;
@Column(name = "name",
nullable = false,
unique = true)
private String name;
@OneToMany(mappedBy = "profileId", fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JsonIgnore
private List<ProfileRoleFactory> roles;```
**ProfileRoleFactory.class**
```java
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Data
@Entity
@Table(name = "profile_role")
public class ProfileRoleFactory {
@EmbeddedId
private ProfileRoleIdFactory id;
@ManyToOne(fetch = FetchType.EAGER)
@MapsId("profileId")
@JoinColumn(name = "profile_id",
updatable = false,
nullable = false,
referencedColumnName = "id",
foreignKey = @ForeignKey(name = "id.profile_id"),
columnDefinition = "CHAR(36)")
private ProfileFactory profileId;
@ManyToOne(fetch = FetchType.EAGER)
@MapsId("roleId")
@JoinColumn(name = "role_id",
nullable = false,
updatable = false,
referencedColumnName = "id",
foreignKey = @ForeignKey(name = "id.role_id"),
columnDefinition = "BIGINT")
private RoleFactory roleId;
@Column(name = "applied_at",
nullable = false,
columnDefinition = "TIMESTAMP WITHOUT TIME ZONE")
private Timestamp appliedAt = new Timestamp(System.currentTimeMillis());```