I receive following error when I save the object using Hibernate
object references an unsaved transient instance - save the transient instance before flushi
My problem was related to @BeforeEach
of JUnit. And even if I saved the related entities (in my case @ManyToOne
), I got the same error.
The problem is somehow related to the sequence that I have in my parent. If I assign the value to that attribute, the problem is solved.
Ex. If I have the entity Question that can have some categories (one or more) and entity Question has a sequence:
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "feedbackSeq")
@Id
private Long id;
I have to assign the value question.setId(1L);