我正在尝试创建社交应用服务。我的用户有确认或未确认的关系。
当我加载UserA时,结果看起来像是爱。
"result":{
"idUser":"UserA",
"unconFriendships":[
{
"idUser":"UserB",
"unconFriendships":[
{
"idUser":"UserC",
"unconFriendships":[
...
虽然它必须看起来像
"result":{
"idUser":"UserA",
"unconFriendships":[
{
"idUser":"UserB",
"unconFriendships":null //only one level have to fetched
....
我认为这是因为杰克逊json库,我重新编写代码。在序列化之前,我检查了userA对象,发现userA.unconFriendships.userB.unconFriendships
不是null
而且size
大于0。
差不多已经12个小时了,仍然无法解决问题。请帮我解决这个问题。谢谢你的到来。
这是UserEntity.java
@Entity
@Table(name="aduser",uniqueConstraints=@UniqueConstraint(columnNames = {"idUser","nmEmail"}))
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="cdUser")
public class UserEntity extends BaseEntity {
protected static final long serialVersionUID = 8864033727886664353L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "admin_seq")
@SequenceGenerator(name = "admin_seq", sequenceName = "CDUSER_SEQUENCE", allocationSize = 1)
@Column(name="cdUser")
private long cdUser;
@OneToMany(mappedBy = "owner", targetEntity=Friendship.class)
@JsonProperty
protected Set<UnconfirmedFriendship> unconFriendships;
@OneToMany(mappedBy = "owner", targetEntity=Friendship.class)
@JsonProperty
protected Set<UnconfirmedFriendship> conFriendships;
...
Friendship.java
@Entity
@Table(name="aduserfriend")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "verified")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="friend_cduser",scope=UserEntity.class)
public abstract class Friendship extends BaseEntity{
protected static final long serialVersionUID = -670863816551430192L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "cdFriendship")
private long cdFriendship;
@ManyToOne
@JsonIgnore
@JoinColumn(name = "owner_cduser")
protected UserEntity owner;
@ManyToOne
@JoinColumn(name = "friend_cduser")
protected UserEntity friend;
@Column(name = "verified",insertable=false,updatable=false)
private boolean verified;
...
UnconfirmedFriendship.java和ConfirmedFriendship.java
@Entity
@DiscriminatorValue(value = "0")//this value is 1 for Confirmed relationship
public class UnconfirmedFriendship extends Friendship {
private static final long serialVersionUID = 57796452166904132L;
}