我有一个名为的contentPath,有可能有同样类型的父实体,以及同类型的儿子,有类似表示:春数据休息多对多树投影映射
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "NAME", length = 50)
@NotNull
private String name;
@Column(name = "DESCRIPTION")
private String description;
@ManyToOne
@JoinColumn(name="CONTENT_PATH_ID")
public ContentPath contentPath;
@OneToMany(mappedBy="contentPath")
public Set<ContentPath> contentPaths;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "ACTIVITY_CONTENT_PATH",
joinColumns = {@JoinColumn(name = "CONTENT_PATH_ID", referencedColumnName = "ID")},
inverseJoinColumns = {@JoinColumn(name = "ACTIVITY_ID", referencedColumnName = "ID")})
private Set<Activity> activities;
我有我的ContentPathRepository将它公开为一个API。
@RepositoryRestResource(collectionResourceRel = "contentPaths", path = "contentPaths", excerptProjection = ContentPathProjection.class)
public interface ContentPathRestRepository extends PagingAndSortingRepository<ContentPath, Long> {
}
和我的投影,它应该正确格式化我的对象。
@Projection(name = "contentPathProjection", types = ContentPath.class)
public interface ContentPathProjection {
Long getId();
String getName();
Set<ContentPath> getContentPaths();
}
我期待得到ContentPaths,其中有内部的ContentPaths的名单,我得到了成功,但它并不带来的ID,它只是把名称和描述,这是很奇怪,因为我的投影没有说明。
电流响应:
"name": "BOOK 1",
"id": 1,
"contentPaths": [
{
"name": "UNIT 1",
"description": "UNIT 1 description"
},
{
"name": "UNIT 2",
"description": "UNIT 2 description"
}
]
为什么会发生?如何解决它?
你对'ContentPath.id'公共的getter? –
是的。 'public long getId(){return id;}' 但奇怪的是它也返回一个描述,但我没有在我的投影中的描述。 –
它也返回第一级的ID,但不是第二级。 –