Constraint error trying to persist with cascade

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, can anyone tell me if everything is correct, if I am forgetting something ... thanks in advance

    
asked by anonymous 01.12.2016 / 14:37

1 answer

2

Can you show the code when you are trying to insert it? Because even though everything is right with the mapping, at the time of the insert, you may not be inserting the reference from one to the other. Example:

Assinatura a = new Assinatura();
a.setDiretriz(objetoDiretriz);
...
objetoDiretriz.getAssinaturas().add(a);
    
01.12.2016 / 16:41