0

I have been trying all day to persist an entity "resultatRAT"

ResultatRAT.class

@Entity
@Table(name = "resultat_rat")
@Inheritance(strategy = InheritanceType.JOINED) 
@DiscriminatorValue("REMBOURSEMENT_TOTAL")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class ResultatRAT extends Resultat implements Serializable {
    private static final long serialVersionUID = 1L;

    @NotNull
    @Column(name = "montant_remboursement", nullable = false)
    private Float montantRemboursement;

    @NotNull
    @Column(name = "pre_solde_dispo", nullable = false)
    private Float preSoldeDispo;

    @NotNull
    @Column(name = "post_solde_dispo", nullable = false)
    private Float postSoldeDispo;

    @NotNull
    @Column(name = "duree_restante", nullable = false)
    private Integer dureeRestante;

    @NotNull
    @Column(name = "pre_echeance", nullable = false)
    private Float preEcheance;

    @NotNull
    @Column(name = "post_echeance", nullable = false)
    private Float postEcheance;

    @NotNull
    @Column(name = "capital_amorti", nullable = false)
    private Float capitalAmorti;

    @NotNull
    @Column(name = "capital_restant_du", nullable = false)
    private Float capitalRestantDu;

    @NotNull
    @Column(name = "mnt_penalite_ht", nullable = false)
    private Float mntPenaliteHT;

    @NotNull
    @Column(name = "taxe_penalite_ht", nullable = false)
    private Float taxePenaliteHT;

// Getters and setter omitted for brevity
}

this is the mother class "Resultat"

Resultat.class

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "resultat")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@DiscriminatorColumn(name = "typeSimulation", discriminatorType = DiscriminatorType.STRING)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME
    , property = "typeSimulation")
@JsonSubTypes(
    {
        @JsonSubTypes.Type(value = ResultatRAP.class, name = "REMBOURSEMENT_PARTIEL"),
        @JsonSubTypes.Type(value = ResultatRAT.class, name = "REMBOURSEMENT_TOTAL"),
    }
)
public abstract class Resultat implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;


    @OneToOne(mappedBy = "resultat", cascade = CascadeType.PERSIST, orphanRemoval = true)
    private Simulation simulation;

    @Column(name = "typeSimulation", nullable = false)
    @Enumerated(EnumType.STRING)
    private TypeSimulation typeSimulation; 
// Getters and setter omitted for brevity
}

but each attempt have been a failure , the post method is pretty standard

 @PostMapping("/resultats")
    public Resultat createResultat(@RequestBody Resultat resultat) throws URISyntaxException {
        if (resultat.getId() != null) {
            throw new BadRequestAlertException("A new resultat cannot already have an ID", ENTITY_NAME, "idexists");
        }
        Resultat result = resultatRepository.save(resultat);
        return result;
    }

and this is my JSON object

   {
            "typeSimulation":"REMBOURSEMENT_TOTAL",
            "montantRemboursement":22.0,
            "preSoldeDispo":2222.0,
            "postSoldeDispo":2.0,
            "dureeRestante":221,
            "preEcheance":341.0,
            "postEcheance":53.0,
            "capitalAmorti":12345.0,
            "capitalRestantDu":235.0,
            "mntPenaliteHT":231.0,
            "taxePenaliteHT":231.0
 }

each time I request my object to be persisted I get this error

Invalid value "1" for parameter "parameterIndex" [90008-200] Logstash

Any idea on how to solve this problem? Thank you very much

Zidani Mehdi
  • 25
  • 2
  • 7
  • is it really necessary to establish `Resultat` with `@Entity` annotation? In my opinion it could be marked as `@MappedSuperclass` only. Apparently hibernate is trying to build the `resultat` table and add a new record to it. – Andrzej Więcławski Nov 28 '21 at 06:48
  • Yes, I find it necessary, since I need it for `@OneToOne` relationships, and `Resultat` can only be one of `Resultat` child types. Thank you – Zidani Mehdi Nov 28 '21 at 09:00
  • Maybe, please believe that: https://stackoverflow.com/a/3827546/11868833 – Andrzej Więcławski Nov 28 '21 at 09:14
  • 1
    Yes looks like I have no choice but to use `MappedSupperClass`,thank you for the suggestion – Zidani Mehdi Nov 28 '21 at 14:57
  • Yoy have `@Inheritance(strategy = InheritanceType.JOINED) ` and `@Discriminator...`, why is that? – pirho Nov 28 '21 at 17:59
  • I discovered later , that i don't need `@Discriminator..` when using joined strategy , but it doesn't affect the outcome – Zidani Mehdi Nov 28 '21 at 21:23

0 Answers0