返回信息关系多对多

时间:2018-12-21 10:04:16

标签: hibernate jpa spring-data-jpa many-to-many entity

我的用户表和个人资料之间有很多关系。所以我创建了一个实体UserProfile

df1=df1.rdd.map(lambda r: ((r.zip_code, r.territory_name), (r.state, r.state1, r.state2)))\
       .reduceByKey(lambda x,y: (x[0] + y[0], x[1] + y[1], x[2] + y[2]))\
       .map(lambda r: (r[0][0],r[0][1],r[1][0],r[1][1],r[1][2]))\
       .toDF(["zip_code","territory_name","state","state1","state2"])
df1.show()
+--------+--------------+-----+------+------+
|zip_code|territory_name|state|state1|state2|
+--------+--------------+-----+------+------+
|   81A01|  TERR NAME 01|   NJ|    NY|    LA|
|   81A02|  TERR NAME 01|   CA|      |    NY|
+--------+--------------+-----+------+------+

当我发现要检索用户的信息时,他没有得到我的个人资料。

这是流json转向

{     “ id”:1     “ email”:“ userEmail”, }

这就是我找回实体的方式:

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

0 个答案:

没有答案