How correctly save two entity to DB?

I have two entity User and Skill. One user can have several skills. First I saved several skills in the table of Skill. When I want to add a User in DB and I want to add a Skill with it. I will use a DTO(User user, String nameOfSkill).

Can you show me a good solution? I use Spring-Boot.

public class User{

@Id

@GeneratedValue(strategy = GenerationType.IDENTITY)

private Long id;

private String firstName;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval =

true)

private List skillOfUser;

}

public class Skill{

@Id

@GeneratedValue(strategy = GenerationType.IDENTITY)

private Long id;

@ManyToOne(fetch = FetchType.LAZY)

private User user;

private String name;

private String...

Read More »

By: StackOverFlow - 7 days ago

Related Posts