我有一個名爲的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,但不是第二級。 –