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{


@GeneratedValue(strategy = GenerationType.IDENTITY)

private Long id;

private String firstName;

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


private List skillOfUser;


public class Skill{


@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