[Java] Linked table empty

Good evening to all.
I have a problem mapping an xml into two table, one main and the other linked. The main table seems ok and fully filled but the other is empty and I cannot understand why.
I need to map this XML fragment and insert infos in two Oracle tables on my db:

<iscrizione-ri n-iscrizione-ri="07236523466" provincia-ri="VC" cciaa-competente="MONTE ROSA LAGHI BASSO PIEMONTE" dt-iscrizione="12/01/2012">
	<sezioni>
		<sezione c="S" descrizione="Iscritta con la qualifica di SOCIETA' SEMPLICE (sezione speciale)" dt-iscrizione="10/02/1990"/>
		<sezione c="G" descrizione="Iscritta con la qualifica di IMPRESA AGRICOLA (sezione speciale)" dt-iscrizione="15/03/1991"/>
	</sezioni>
</iscrizione-ri>

So, I have created these 2 tables:

CREATE TABLE IC_ISCRIZIONE_RI 
(
  ID NUMBER(19) NOT NULL 
, N_ANNOTAZIONE_RI VARCHAR2(20) 
, N_ISCRIZIONE_RI VARCHAR2(20) 
, CODICE_FISCALE VARCHAR2(16) 
, N_ANNOTAZIONE_RI_OLD VARCHAR2(20) 
, N_ISCRIZIONE_RI_OLD VARCHAR2(20) 
, PROVINCIA_RI VARCHAR2(2) 
, CCIAA_COMPETENTE VARCHAR2(255) 
, C_N_ISCRIZIONE_RI_OLD VARCHAR2(20) 
, DATA_ISCRIZIONE VARCHAR2(19) 
, DATA_ANNOTAZIONE VARCHAR2(19) 
, PAC_IC_ANAG_ID NUMBER(19) NOT NULL
, CONSTRAINT IC_ISCRIZIONE_RI_ID_PK PRIMARY KEY 
  (
    ID 
  )
  ENABLE 
);
ALTER TABLE "CERT_OPERATORI"."IC_ISCRIZIONE_RI" ADD CONSTRAINT IC_ISCRIZIONE_RI_FK1 FOREIGN KEY (PAC_IC_ANAG_ID) REFERENCES PAC_IC_ANAG(ID) ON DELETE CASCADE ENABLE;

and

CREATE TABLE IC_SEZIONE 
(
  ID NUMBER(19) NOT NULL 
, C_CODICE VARCHAR2(3) 
, DESCRIZIONE VARCHAR2(255) 
, DATA_ISCRIZIONE VARCHAR2(19) 
, FLAG_COLTIV_DIRETTO VARCHAR2(4) 
, CCIAA_AA VARCHAR2(2) 
, N_AA VARCHAR2(10) 
, FLAG_ATTESA_DECISIONE VARCHAR2(4) 
, DATA_DECORRENZA VARCHAR2(19) 
, IC_ISCRIZIONE_RI_ID NUMBER(19) NOT NULL 
, CONSTRAINT IC_SEZIONE_PK PRIMARY KEY 
  (
    ID 
  )
  ENABLE 
);
 alter table "CERT_OPERATORI"."IC_SEZIONE" add constraint ID_IC_ISCRIZIONE_RI_FK foreign key("IC_ISCRIZIONE_RI_ID") references "IC_ISCRIZIONE_RI"("ID") ON DELETE CASCADE ENABLE;

I mapped these tables to two Entities:


import com.fasterxml.jackson.annotation.JsonView;
import it.gse.pacifica.entity.anagrafica.ic.IcAnagEntity;
import it.infocamere.gemo.View;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import javax.persistence.*;
import javax.xml.bind.annotation.*;
import java.util.List;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
      "sezioni",
      "nAnnotazioneRi",
      "nIscrizioneRi",
      "codiceFiscale",
      "nAnnotazioneRiOld",
      "nIscrizioneRiOld",
      "provinciaRi",
      "cciaaCompetente",
      "cNIscrizioneRiOld",
      "dataIscrizione",
      "dataAnnotazione"
})
@XmlRootElement(name = "iscrizione-ri")
@Entity(name = "IscrizioneRi")
@Table(name = "IC_ISCRIZIONE_RI")
public class IscrizioneRi {

   @Getter @Setter
   @Id
   @Column(name = "ID")
   @GeneratedValue(generator="iscrizioneRi_id_generator")
   @GenericGenerator(
         name="iscrizioneRi_id_generator",
         strategy="foreign",
         parameters=@org.hibernate.annotations.Parameter(
               name="property",
               value="icAnagEntity"
         )
   )
   @XmlAttribute(name = "Id")
   @JsonView({ View.IcSchemaView.class })
   protected Long id;

   @Getter @Setter
   @OneToOne(fetch = FetchType.LAZY, optional = false, targetEntity = IcAnagEntity.class)
   @OnDelete(action = OnDeleteAction.CASCADE)
   @PrimaryKeyJoinColumn(foreignKey = @ForeignKey(name = "IC_ISCRIZIONE_RI_FK1"))
   @XmlTransient
   protected IcAnagEntity icAnagEntity;

   […]

   @Getter @Setter
   @Basic
   @Column(name = "DATA_ANNOTAZIONE", length = 19)
   @XmlAttribute(name = "dt-annotazione")
   @JsonView({ View.IcXmlView.class, View.IcSchemaView.class })
   protected String dataAnnotazione;

   @Getter @Setter
   @XmlElementWrapper(name = "sezioni")
   @XmlElement(name = "sezione")
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   @JoinColumn(name = "IC_ISCRIZIONE_RI_ID", foreignKey=@ForeignKey(name="ID_IC_ISCRIZIONE_RI_FK"))
   @OnDelete(action = OnDeleteAction.CASCADE)
   @JsonView({ View.IcXmlView.class, View.IcSchemaView.class })
   protected List<Sezione> sezioni;
}

and

package it.infocamere.gemo.sezioni;

import com.fasterxml.jackson.annotation.JsonView;
import it.infocamere.gemo.View;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.xml.bind.annotation.*;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
      "id",
      "cCodice",
      "descrizione",
      "dataIscrizione",
      "flagColtivatoreDiretto",
      "cciaaAa",
      "nAa",
      "flagAttesaDecisione",
      "dataDecorrenza",
      "icIscrizioneRiId"
})
@XmlRootElement(name = "sezione")
@Entity(name = "Sezione")
@Table(name = "IC_SEZIONE")
public class Sezione {

   @Getter
   @Setter
   @Id
   @Column(name = "ID")
   @GeneratedValue(strategy = GenerationType.AUTO)
   @JsonView({ View.IcSchemaView.class })
   protected Long id;

[…]

   @Getter @Setter
   @Basic
   @Column(name = "IC_ISCRIZIONE_RI_ID", length = 19)
   @JsonView({ View.IcXmlView.class, View.IcSchemaView.class })
   protected Long icIscrizioneRiId;


}

When I execute the program, the primary table IC_ISCRIZIONE_RI works fine and it is fully valorized, but the linked table IC_SEZIONI is empty and into the log I see this error:


14:20:25.853><PacificaWorker><ERROR><org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions[142]><org.hibernate.engine.jdbc.spi.SqlExceptionHelper><SimpleAsyncTaskExecutor-1><ORA-01400: cannot insert NULL into ("CERT_OPERATORI"."IC_SEZIONE"."IC_ISCRIZIONE_RI_ID")

The “IC_SEZIONE”.“IC_ISCRIZIONE_RI_ID” is the key field that links the IC_SEZIONE table to the IC_ISCRIZIONE_RI main table, and must contain the IC_ISCRIZIONE_RI.ID value.

These are the values read from the xml:


14:20:25.710><PacificaWorker><DEBUG><it.gse.pacifica.worker.writer.VisuraXmlDBWriter.write[93]><it.gse.pacifica.worker.writer.VisuraXmlDBWriter><SimpleAsyncTaskExecutor-1><**IscrizioneRI**: IscrizioneRi{id=null, nAnnotazioneRi='null', nIscrizioneRi='07236523466', codiceFiscale='null', nAnnotazioneRiOld='null', nIscrizioneRiOld='null', provinciaRi='VC', cciaaCompetente='MONTE ROSA LAGHI BASSO PIEMONTE', cNIscrizioneRiOld='null', dataIscrizione='12/01/2012', dataAnnotazione='null', **sezioni**=[**Sezione**{id=null, cCodice='S', descrizione='Iscritta con la qualifica di SOCIETA' SEMPLICE (sezione speciale)', dataIscrizione='10/02/1990', flagColtivatoreDiretto='null', cciaaAa='null', nAa='null', flagAttesaDecisione='null', dataDecorrenza='null'}, **Sezione**{id=null, cCodice='G', descrizione='Iscritta con la qualifica di IMPRESA AGRICOLA (sezione speciale)', dataIscrizione='15/03/1991', flagColtivatoreDiretto='null', cciaaAa='null', nAa='null', flagAttesaDecisione='null', dataDecorrenza='null'}]}><>

As you can see the ids are null but into the IC_ISCRIZIONE_RI table Hibernates writes them.
immagine

What am I doing wrong?
Thank you very much

I solved it by removing the mandatory not null from the “IC_SECTION”.“IC_ISCRIZIONE_RI_ID” field.
By doing so it appears that all values are written. I hope it will be useful to someone.
Thank you