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);
}