Bonjour à toutes et à tous
mon probleme :
lors de la création de ma table bien, j'aimerai recupperé un attribut auto créé par un trigger actif sur cette table mais je n'y arrive pas.. cet attribut c'est la colonne superid. pour tant, à chaque création de bien, ce trigger fonction parfetement.
voila ma class:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 @Entity @Getter @Setter @NoArgsConstructor @AllArgsConstructor public class Bien { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @ManyToOne @JoinColumn(name = "type") private Type_bien type; @Column private int prix; @Column private int npmin; @Column private int npmax; @Column private int nchambre; @Column private int nsdb; @Column private int nwc; @Column private int superficie; @Column private String aladisposition; @Column private String description; @ManyToOne @JoinColumn(name = "coordonnee") private Coordonnee coordonnee; @ManyToOne @JoinColumn(name = "appartient") private Personne appartient; @Column private LocalDateTime dateCreation; @OneToMany(mappedBy = "bien_reserve") private List<Reservation> de_reservation; @Column private int superid; }
voila mon controleur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 @PostMapping("/creatt") @ResponseStatus(HttpStatus.OK) public int creatBient(@RequestBody BienDTO bienDTO) throws BienExisteExeption, NoSuchAlgorithmException, InvalidKeySpecException { return ((BienService)service).creatKey(bienDTO); }
voila mon service:
voila mon Mapper:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 @Transactional public int creatKey(BienDTO toCreat) throws BienExisteExeption, NoSuchAlgorithmException, InvalidKeySpecException { if (bienRepository.existsById(toCreat.getId())) throw new BienExisteExeption(toCreat.getId()); actionDTO.setId(0); actionDTO.setDate(LocalDateTime.now()); actionDTO.setClassName("Bien"); actionDTO.setIdClasse(toCreat.getId()); actionDTO.setAction("Création"); actionDTO.setDescription("Création de/d' " +toCreat.getType_bien().getNom() + " bien à " + toCreat.getCoordonnee().getVille().getNom_ville() + " dans la province de " + toCreat.getCoordonnee().getVille().getProvince().getNomprovince() + " par " + toCreat.getAppartient().getNom() + "-" + toCreat.getAppartient().getPrenom()); actionRepository.save(actionMapper.toEntity(actionDTO)); Bien entity = bienMapper.toEntity(toCreat); coordorRepository.save(entity.getCoordonnee()); return bienMapper.toDTO(bienRepository.save(entity)).getSuperid(); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 @Component public class BienMapper implements Mapper<BienDTO, Bien>{ @Autowired private Mapper<ReservationDTO, Reservation> reservationMapper; @Autowired private Mapper<PersonneSimplifierDTO, Personne> personneMapper; @Autowired private Mapper<Type_bienDTO, Type_bien> type_bienMapper; @Autowired private Mapper<CoordonneeDTO, Coordonnee> coordonneeMapper; @Autowired private Type_bienRepository type_bienRepository; @Autowired private PersonneReposytory personneReposytory; @Override public BienDTO toDTO(Bien bien) { if (bien==null) return null; return new BienDTO( bien.getId(), type_bienMapper.toDTO(bien.getType()), bien.getPrix(), bien.getNpmin(), bien.getNpmax(), bien.getNchambre(), bien.getNsdb(), bien.getNwc(), bien.getSuperficie(), bien.getAladisposition(), bien.getDescription(), coordonneeMapper.toDTO(bien.getCoordonnee()), personneMapper.toDTO(bien.getAppartient()), bien.getDateCreation(), bien.getSuperid() ); } @Override public Bien toEntity(BienDTO bienDTO) throws NoSuchAlgorithmException, InvalidKeySpecException { if (bienDTO==null) return null; Bien bien = new Bien(); bien.setId(bienDTO.getId()); bien.setType(type_bienRepository.getOne(bienDTO.getType_bien().getId())); bien.setPrix(bienDTO.getPrix()); bien.setNpmin(bienDTO.getNpmin()); bien.setNpmax(bienDTO.getNpmax()); bien.setNchambre(bienDTO.getNchambre()); bien.setNsdb(bienDTO.getNsdb()); bien.setNwc(bienDTO.getNwc()); bien.setSuperficie(bienDTO.getSuperficie()); bien.setAladisposition(bienDTO.getAladisposition()); bien.setDescription(bienDTO.getDescription()); bien.setCoordonnee(coordonneeMapper.toEntity(bienDTO.getCoordonnee())); bien.setAppartient(personneReposytory.getOne(bienDTO.getAppartient().getId())); bien.setDateCreation(LocalDateTime.now()); bien.setSuperid(bienDTO.getSuperid()); return bien ; } }
et voila ma table et mon trigger:
En fesant:
j'arrive tres bien a recup la nouvelle id créé ... pourquoi avec:
Code : Sélectionner tout - Visualiser dans une fenêtre à part return bienMapper.toDTO(bienRepository.save(entity)).getId()
la valeur reste vide????? car elle est créé en même temps que les autres atribue... meme avant!
Code : Sélectionner tout - Visualiser dans une fenêtre à part return bienMapper.toDTO(bienRepository.save(entity)).getSuperid();
dans l'attente de/vous lire voir/lire
bien à vous
Partager