在我的Spring-Boot项目中,有一个实体类'PersonEntity'和'TptEntity'用于PersonEntity和其他实体之间的关系。
我在TptEntity中使用embeddableId可以正常工作。
@Embeddable
public class TptId implements Serializable {
@ManyToOne
@JoinColumn(name = "PersonenID", referencedColumnName = "ID")
@JsonIgnoreProperties("tpt")
PersonEntity person;
...
}
@Entity
@Table(name = "Tpt")
public class TptEntity {
@EmbeddedId
TptId id;
...
}
在PersonEntity中,OneToMany关系的声明如下:
@OneToMany(mappedBy = "id.person")
@JsonIgnoreProperties("person")
List<TptEntity> tpt;
问题是,JsonIgnoreProperties不能与EmbeddedId一起使用。我还尝试将其更改为@JsonIgnoreProperties("id.person")
,这是它与mapedBy一起工作的方式,但这无济于事。
一个人的json包含以下内容:
{ "id" : 1,
"tpt": [
{
"id":
{
"person": { "id" : 1},
...
},
...
} ,
...
]
}
我不会陷入无限递归中,因为@JsonIgnoreProperties("tpt")
中的TptId
有效,因此问题并不大。但是我想知道如何摆脱对同一个人的提法。