Spring data REST links onetomany 和 manytomany 关系的空结果

Spring data REST links empty result for onetomany and manytomany relations

我有两个类如下

@Entity
@Table(name = "Employee", schema = "...", catalog = "...")
public class EmployeeEntity implements Serializable, UserDetails {

    @Id()
    @Column(name = "EmployeeID", nullable = false, insertable = true, updatable = true, length = 20)

    @Basic
    @Column(name = "UserName", nullable = true, insertable = true, updatable = true, length = 20)
    private String username;


    @OneToMany
    @JoinColumn(name="UserName")    
    private Set<EmployeesGroupsEntity> employeeGroups;



 //Getter and setters
}

@Entity
@Table(name = "EmployeesGroups", schema = "...", catalog = "...")
public class EmployeesGroupsEntity implements  Serializable {

    @Id
    @Column(name = "UserName", nullable = false, insertable = true, updatable = true, length = 20)
    private String username;

    @Basic
    @Column(name = "Group", nullable = false, insertable = true, updatable = true, length = 255)    
    private String groups; 

}

现在,要访问 objects,我有 spring 数据存储库,如下所示

@RepositoryRestResource(collectionResourceRel = "Employee", path = "Employee")
public interface IEmployeeRepository extends PagingAndSortingRepository<EmployeeEntity, String>  {

    EmployeeEntity getByUsername(String userName);

    EmployeeEntity getByEmailAddress(String emailAddress);
}

@RepositoryRestResource(collectionResourceRel = "EmployeesGroups", path = "EmployeesGroups")
public interface IEmployeesGroupsRepository extends PagingAndSortingRepository<EmployeesGroupsEntity,String> {

}

通过上述设置,我尝试访问 URL

http://localhost:8080/Employee/12345

我成功得到如下结果

{
  "employeeId" : "12345",
  "username" : "firstx",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/Employee/12345"
    },
    "employeeGroups" : {
      "href" : "http://localhost:8080/Employee/12345/employeeGroups"
    }
  }
}

作为下一步,当我访问 URL

 http://localhost:8080/Employee/12345/employeeGroups

我得到的输出是

{ }

后来,我也尝试用header"text/uri-list"。当我这样做时,我得到了 204 的响应代码。

请帮我解决这个问题。

谢谢

放弃后..在遇到另一个问题后找到答案.

我只需要注释与 RestResource(exported=true) 的关系

@Entity
@Table(name = "Employee", schema = "...", catalog = "...")
public class EmployeeEntity implements Serializable, UserDetails {

    @Id()
    @Column(name = "EmployeeID", nullable = false, insertable = true, updatable = true, length = 20)

    @Basic
    @Column(name = "UserName", nullable = true, insertable = true, updatable = true, length = 20)
    private String username;


    @OneToMany
    @RestResource(exported = true)
    @JoinColumn(name="UserName")    
    private Set<EmployeesGroupsEntity> employeeGroups;



 //Getter and setters
}