IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JPA Java Discussion :

Impossible de recupérer une valeur


Sujet :

JPA Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2020
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2020
    Messages : 16
    Points : 12
    Points
    12
    Par défaut Impossible de recupérer une valeur
    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:
    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();
        }
    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
    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:
    Nom : attribut1.PNG
Affichages : 86
Taille : 31,6 Ko
    Nom : attribut2.PNG
Affichages : 87
Taille : 24,2 Ko

    En fesant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    return bienMapper.toDTO(bienRepository.save(entity)).getId()
    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)).getSuperid();
    la valeur reste vide????? car elle est créé en même temps que les autres atribue... meme avant!


    dans l'attente de/vous lire voir/lire
    bien à vous

  2. #2
    Membre éclairé

    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    461
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 461
    Points : 894
    Points
    894
    Billets dans le blog
    5
    Par défaut
    Bonjour,

    Pour commencer, il serait bon ton de respecter les convention de nommage Java:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    private Type_bien type;
    private List<Reservation> de_reservation;
    En convention Java, c'est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    private TypeBien type;
    private List<Reservation> deReservation;
    En ce qui concerne le coeur de ton problème:
    Tu sauvegarde en BDD un truc. Hibernate te remonte les information du truc sauvegardé juste après la sauvegarde.
    Le trigger doit, je pense, s'appliquer après.

    Cordialement.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2020
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2020
    Messages : 16
    Points : 12
    Points
    12
    Par défaut
    salut et merci d'avoir pris le temps de me repondre

    1) jha oui desolé je viens de voir quand tu dis respecter les convantion


    2 le trigger est un "befor" du coup elle doit se faire avant. ou c'est moi qui voit le probleme à l'envert :'(

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 09/10/2016, 18h40
  2. Réponses: 5
    Dernier message: 24/05/2006, 14h04
  3. Réponses: 17
    Dernier message: 22/04/2006, 12h24
  4. comment recupérer une valeur dans un datagrid
    Par budylove dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 23/02/2006, 17h04
  5. impossible d'attribuer une valeur a un objet
    Par el_quincho dans le forum Access
    Réponses: 2
    Dernier message: 10/01/2006, 11h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo