I’m developing a user registration form, the problem I get is that when I want to test my web service in postman it shows me the following error in my eclipse console:
2020-06-02 19:50:04.559 WARN 1576 --- [nio-8484-exec-2] > o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1400, SQLState: > 23000 2020-06-02 19:50:04.560 ERROR 1576 --- [nio-8484-exec-2] > o.h.engine.jdbc.spi.SqlExceptionHelper : ORA-01400: impossible > d'insérer NULL dans ("NAWFEL"."ORDO_DEP_UTILISATEUR"."EMPLOI") > > 2020-06-02 19:50:04.582 ERROR 1576 --- [nio-8484-exec-2] > o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for > servlet [dispatcherServlet] in context with path [] threw exception > [Request processing failed; nested exception is > org.springframework.dao.DataIntegrityViolationException: could not > execute statement; SQL [n/a]; constraint [null]; nested exception is > org.hibernate.exception.ConstraintViolationException: could not > execute statement] with root cause > > oracle.jdbc.OracleDatabaseException: ORA-01400: impossible d'insérer > NULL dans ("NAWFEL"."ORDO_DEP_UTILISATEUR"."EMPLOI") > > at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:513) > ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0] at > oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:461) > ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0] at > oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1104) > ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0] at > oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:550) > ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0] at > oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:268) > ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0] at > oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:655) > ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
he tells me that I cannot insert a null value in the job “emploi” column, but I entered the value of the job column in my postman as you can see here:
this is my entity code :
package com.app.habilitation.entity; import java.sql.Date; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; @Entity @Table(name="ORDO_DEP_UTILISATEUR") public class UserEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="IDENTIFIANT") private Integer IDENTIFIANT; @ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) @JoinColumn(name="EMPLOI") private EmploiEntity emploi; @ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) @JoinColumn(name="ENTITE") private EntiteEntity entite; @Column(name="LOGIN") private String login; @Column(name="MOTDEPASSE") private String mdp; @Column(name="NOM") private String nom; @Column(name="PRENOM") private String prenom; @Column(name="CREEPAR") private Integer creerpar; @Column(name="ANNULEPAR") private Integer annulepar; @Column(name="STATUT") private String statut; @Column(name="DATEEFFET") private Date dateeffet; @Column(name="DATEFIN") private Date datefin; @Column(name="CREELE") private Date creele; @Column(name="MOTIFDEDESACTIVATION") private String motifdedesactivation; @Column(name="ANNULELE") private Date annulele; @Column(name="EMAIL") private String email; @Column(name="CONFIRMATIONMOTDEPASSE") private String confirmation_mot_de_passe; public String getConfirmation_mot_de_passe() { return confirmation_mot_de_passe; } public void setConfirmation_mot_de_passe(String confirmation_mot_de_passe) { this.confirmation_mot_de_passe = confirmation_mot_de_passe; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public Integer getIDENTIFIANT() { return IDENTIFIANT; } public void setIDENTIFIANT(Integer iDENTIFIANT) { IDENTIFIANT = iDENTIFIANT; } public EmploiEntity getEmploi() { return emploi; } public void setEmploi(EmploiEntity emploi) { this.emploi = emploi; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getMdp() { return mdp; } public void setMdp(String mdp) { this.mdp = mdp; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } public Integer getCreerpar() { return creerpar; } public void setCreerpar(Integer creerpar) { this.creerpar = creerpar; } public Integer getAnnulepar() { return annulepar; } public void setAnnulepar(Integer annulepar) { this.annulepar = annulepar; } public String getStatut() { return statut; } public void setStatut(String statut) { this.statut = statut; } public Date getDateeffet() { return dateeffet; } public void setDateeffet(Date dateeffet) { this.dateeffet = dateeffet; } public Date getDatefin() { return datefin; } public void setDatefin(Date datefin) { this.datefin = datefin; } public Date getCreele() { return creele; } public void setCreele(Date creele) { this.creele = creele; } public String getMotifdedesactivation() { return motifdedesactivation; } public void setMotifdedesactivation(String motifdedesactivation) { this.motifdedesactivation = motifdedesactivation; } public Date getAnnulele() { return annulele; } public void setAnnulele(Date annulele) { this.annulele = annulele; } public EntiteEntity getEntite() { return entite; } public void setEntite(EntiteEntity entite) { this.entite = entite; } public UserEntity(EmploiEntity emploi, EntiteEntity entite, String login, String mdp, String nom, String prenom, Integer creerpar, Integer annulepar, String statut, Date dateeffet, Date datefin, Date creele, String motifdedesactivation, Date annulele, String email, String confirmation_mot_de_passe) { this.emploi = emploi; this.entite = entite; this.login = login; this.mdp = mdp; this.nom = nom; this.prenom = prenom; this.creerpar = creerpar; this.annulepar = annulepar; this.statut = statut; this.dateeffet = dateeffet; this.datefin = datefin; this.creele = creele; this.motifdedesactivation = motifdedesactivation; this.annulele = annulele; this.email = email; this.confirmation_mot_de_passe = confirmation_mot_de_passe; } public UserEntity() { } @Override public String toString() { return "UserEntity [IDENTIFIANT=" + IDENTIFIANT + ", emploi=" + emploi + ", entite=" + entite + ", login=" + login + ", mdp=" + mdp + ", nom=" + nom + ", prenom=" + prenom + ", creerpar=" + creerpar + ", annulepar=" + annulepar + ", statut=" + statut + ", dateeffet=" + dateeffet + ", datefin=" + datefin + ", creele=" + creele + ", motifdedesactivation=" + motifdedesactivation + ", annulele=" + annulele + ", email=" + email + ", confirmation_mot_de_passe=" + confirmation_mot_de_passe + "]"; } }
and this is my dao ( i use jpa) :
package com.app.habilitation.dao; import org.springframework.data.jpa.repository.JpaRepository; import com.app.habilitation.entity.UserEntity; public interface UserDao extends JpaRepository<UserEntity, Integer> { }
and this is my userService :
package com.app.habilitation.service; import java.util.List; import com.app.habilitation.entity.UserEntity; public interface UserService { public void save (UserEntity theUser); }
and this is my userServiceImpl :
package com.app.habilitation.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.app.habilitation.dao.UserDao; import com.app.habilitation.entity.UserEntity; @Service public class UserServiceImpl implements UserService { private UserDao userDao; @Autowired public UserServiceImpl (UserDao theuserDao) { userDao = theuserDao; } @Override @Transactional public void save(UserEntity theUser) { userDao.save(theUser); } }
and this is my controller :
package com.app.habilitation.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.app.habilitation.entity.UserEntity; import com.app.habilitation.service.UserService; @SpringBootApplication @RestController @CrossOrigin(origins = "*") //@RequestMapping("/user") public class UserController { private UserService userService; @Autowired public UserController (UserService theuserService) { userService=theuserService; } @GetMapping("/") public String login() { return "authenticaated succesfully"; } @GetMapping("/getUsers") public String getUsers() { return "users"; } @PostMapping("/addUser") public UserEntity addUser (@RequestBody UserEntity theUser) { System.out.println("test"); userService.save(theUser); return theUser; } }
and this is my table user (i use oracle 10g) :
can someone help me please ??
Advertisement
Answer
Can you try to send them as an objects like this
{ "emploi":{"IDENTIFIANT":1} // and so on for any object }