1

I'm looking for a way to save an object with a field of type Set that has a many to many relationship, I get this Set with only the Id attribute informed. but I come across the error "unsaved transient instance", I would like to be able to save this set without having to receive the object with all the attributes, only with the ID.

@ManyToMany
@JoinTable(
        name = "examclinic_term", 
        joinColumns = { @JoinColumn(name = "idexamclinic") }, 
        inverseJoinColumns = { @JoinColumn(name = "idterm") }
    )
Set<Term> terms = new HashSet<>();

my entity

@Entity
public class Term {
    @ID
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private String description;
    private String html;
}

json

[
  {
    "id": 1
  },
  {
    "id": 2
  },
  {
    "id": 3
  }
]

error

object references an unsaved transient instance - save the transient instance before flushing

0 Answers0