Return information relation many-to-many

杀马特。学长 韩版系。学妹 提交于 2020-01-16 19:11:26

问题


I have a manytomany relationship between my user table and profile. So I created a entity UserProfile

public class User implements Serializable {
private static final long serialVersionUID = 1L;

@Id
private Integer id;

private String email;
@JsonBackReference
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<UserProfile> userProfiles = new ArrayList<UserProfile>();

public User() {
}

  GETTER / SETTER
}


public class Profile implements Serializable {
private static final long serialVersionUID = 1L;

@Id
private Integer id;

private String libelleProfile;

@JsonManagedReference
@OneToMany(mappedBy="profile", cascade = CascadeType.ALL)
private List<UserProfile> userProfiles = new ArrayList<UserProfile>();

GETTER / SETTER
}

public class UserProfile implements Serializable {
private static final long serialVersionUID = 1L;

@Id
private Integer id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idUser")
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idProfile")
private Profile profile;
}

When I do a find to retrieve my user’s information, he doesn’t get me his profile.

Here is the flow json turned

{ "id": 1, "email": "userEmail", }

That’s how I get my entity back :

//In my service
userRepository.findByEmail(email);

public interface IUserRepository extends JpaRepository<User, 
Integer>{
   User findByEmail(String email);
}

来源:https://stackoverflow.com/questions/53882726/return-information-relation-many-to-many

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!