Constraint error while trying to persist with Cascade

Asked

Viewed 228 times

1

Good morning, I have the following problem

Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: não é possível inserir NULL em ("XXGOVC"."ASSINATURA"."ID_DIRETRIZ")

And here is the mapping of my entities...

@Entity
@Table(name = "DIRETRIZ")
public class Diretriz {

@Id
@Column(name = "ID_DIRETRIZ", nullable = false)
@GeneratedValue(generator="ID_DIRETRIZ_SEQ", strategy=GenerationType.SEQUENCE)
@SequenceGenerator(sequenceName="ID_DIRETRIZ_SEQ", name="ID_DIRETRIZ_SEQ", allocationSize=1)
private Long idDiretriz;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "diretriz", orphanRemoval=true)
private Set<Assinatura> assinaturas;

and...

@Entity
@Table(name = "ASSINATURA")
public class Assinatura{    

    @Id
    @Column(name = "ID_ASSINATURA", nullable = false)
    @GeneratedValue(generator="ID_ASSINATURA_SEQ", strategy=GenerationType.SEQUENCE)
    @SequenceGenerator(sequenceName="ID_ASSINATURA_SEQ", name="ID_ASSINATURA_SEQ", allocationSize=1)
    private Long idAssinatura;      


    @ManyToOne
    @JoinColumn(name = "ID_DIRETRIZ")
    private Diretriz diretriz;

I have already researched and read the documentation and apparently the mappings are all correct, will someone tell me if this is all right, if I’m forgetting something... I thank you in advance

1 answer

2


Can you show the code of when you are trying to enter? Because even though everything is right with the mapping, at the time of the Insert, possibly Voce is not inserted the reference to each other. Example:

Assinatura a = new Assinatura();
a.setDiretriz(objetoDiretriz);
...
objetoDiretriz.getAssinaturas().add(a);
  • Thanks for the reply, I really did not know it was necessary to do this, even so I did as you said and it did not work

  • Guy was really this, the first time did not give because I still had one more list that was not doing it... vlw even

  • I got it...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.