有些实体具有复合主键,并且这些实体在公开时具有错误的链接,在_links中的URL中具有类的完全限定名称
点击链接也会出现这样的错误 -
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type com.core.connection.domains.UserFriendshipId
Run Code Online (Sandbox Code Playgroud)
我有XML配置的Spring Repository和jpa:启用了存储库,还有从JpaRepository扩展的Respository
我可以使用Repository实现org.springframework.core.convert.converter.Converter来处理这个问题.目前获得如下链接 -
_links: {
userByFriendshipId: {
href: "http://localhost:8080/api/userFriendships/com.core.connection.domains.UserFriendshipId@5b10/userByFriendId"
}
Run Code Online (Sandbox Code Playgroud)
在xml配置中,我在存储库中启用了jpa:repositories和@RestResource
我使用spring数据rest进行分析。但是,当实体具有复合主键时,我不知道如何通过提供主键来获得实体。
河类:
@Entity
public class River {
private RiverPK id;
private Double length;
private Timestamp date;
private String comment;
@Basic
@Column(name = "length")
public Double getLength() {
return length;
}
public void setLength(Double length) {
this.length = length;
}
@Basic
@Column(name = "date")
public Timestamp getDate() {
return date;
}
public void setDate(Timestamp date) {
this.date = date;
}
@Basic
@Column(name = "comment")
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
@Id …Run Code Online (Sandbox Code Playgroud) 我有一个 JPA 实体Person和一个实体Team。两者都由实体PersonToTeam加入。该加入实体与Person保持多对一关系,与Team保持一对一关系。它有一个多列键,由Person和Team的 id 组成,由 @EmbeddedId 表示。为了将嵌入的 id 来回转换为请求 id,我有一个转换器。所有这些都遵循Spring Data REST @Idclass not recognize 的建议
代码如下所示:
@Entity
public class PersonToTeam {
@EmbeddedId
@Getter
@Setter
private PersonToTeamId id = new PersonToTeamId();
@ManyToOne
@Getter
@Setter
@JoinColumn(name = "person_id", insertable=false, updatable=false)
private Person person;
@ManyToOne
@Getter
@Setter
@JoinColumn(name = "team_id", insertable=false, updatable=false)
private Team team;
@Getter
@Setter
@Enumerated(EnumType.STRING)
private RoleInTeam role;
public enum RoleInTeam {
ADMIN, …Run Code Online (Sandbox Code Playgroud)