Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

Java Spring Boot Note save DAO

I have an application coded in Angular on the front and Java Spring boot on the back with MySQL (phpMyadmin).

AND I don't understand why when I but up to date it doesn't always work. if I change the 'company' it ok, But if i change only 'envTech' it don't work.

@Entity
@Table(name="experiences")
@NamedQuery(name="Experience.findAll", query="SELECT e FROM Experience e")
public class Experience implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    private String company;

    private String date;

    @Column(name="env_tech")
    private String envTech;

    //bi-directional many-to-one association to Resume
    @JsonIgnore
    @ManyToOne
    @JoinColumn(name="resume")
    private Resume resumeBean;

    //bi-directional many-to-one association to Mission
    @OneToMany(mappedBy="experience")
    private List<Mission> missions;

@Entity
@Table(name="resumes")
@NamedQuery(name="Resume.findAll", query="SELECT r FROM Resume r")
public class Resume implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    //bi-directional many-to-one association to Paragraph
    @OneToMany(mappedBy="resumeBean")
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<Paragraph> paragraphs;

    //bi-directional many-to-one association to Experience
    @OneToMany(mappedBy="resumeBean")
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<Experience> experiences;

    //bi-directional many-to-one association to Skill
    @OneToMany(mappedBy="resumeBean")
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<Skill> solution;

    //bi-directional many-to-one association to Condition
    @ManyToOne
    @JoinColumn(name="condition")
    private Condition condition;

    //bi-directional many-to-one association to Profil
    @ManyToOne
    @JoinColumn(name="profil")
    private Profil profil;
 @PutMapping(value = "/allresumes/{id}")
    public boolean updateResume(@PathVariable int id, @RequestBody Resume resume) {
    ...
    resume.getExperiences().forEach(experience -> {
            expUpdt =expService.getExperienceById(experience.getId());
            if (expUpdt == null) {
            ...
            } else {
                /*
                public void setResumeBean(Resume resumeBean) {
                        this.resumeBean = resumeBean;
                    }
                */
                experience.setResumeBean(resume);
                experience.getMissions().forEach(mission -> {
                    Mission missionUpt = missionService.getMissionByProject(mission.getProject());
                    if(missionUpt==null){
                        missionUpt = mission;
                        missionUpt.setExperience(experience);
                        logger.info("NULL MISSION" +missionUpt);
                        missionService.saveMission(missionUpt);
                    }else{
                        logger.info("NOT NULL MISSION" +mission);
                        mission.setExperience(experience);
                        missionService.updateMission(mission);
                    }
                
                });
            }
            
    }
}

And I don't know what to show you as a code without giving you all

And the update comes from updateResume . Resume is an object contentement a lot of list as experience that had even on lists

I don't understand why and When 'experience.getMissions().forEach(mission -> {...}' do my save and don't save if only 'envTech' edited.

question from:https://stackoverflow.com/questions/65939750/java-spring-boot-note-save-dao

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...