相关疑难解决方法(0)

Spring Data REST @Idclass无法识别

我有一个名为EmployeeDepartment的实体,如下所示

@IdClass(EmployeeDepartmentPK.class) //EmployeeDepartmentPK is a serializeable object
@Entity
EmployeeDepartment{

@Id
private String employeeID;

@Id
private String departmentCode;
---- Getters, Setters and other props/columns
}
Run Code Online (Sandbox Code Playgroud)

我有一个Spring Data Repository,如下所示

@RepositoryRestResource(....)
public interface IEmployeeDepartmentRepository extends PagingAndSortingRepository<EmployeeDepartment, EmployeeDepartmentPK> {

}
Run Code Online (Sandbox Code Playgroud)

此外,我有一个注册转换器从String转换为EmployeeDepartmentPK.

现在,对于一个由ID employeeID ="abc123"和departmentCode ="JBG"限定的实体,我希望在调用SDR接口时使用的ID是abc123_JBG.例如,http:// localhost/EmployeeDepartment/abc123_JBG应该获取结果,事实确实如此.

但是,当我尝试使用PUT保存实体时,Spring Data Commons的BasicPersistentEntity类中可用的ID属性的departmentCode值为abc123_JBG.这是错的.我不确定这是否是预期的行为.

请帮忙.

谢谢!

spring hibernate jpa spring-data spring-data-rest

8
推荐指数
2
解决办法
3689
查看次数

带有复合主键的Spring数据表

我使用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)

java spring composite-primary-key spring-data-rest

6
推荐指数
2
解决办法
1万
查看次数