2017-04-07 3 views
1

OwnerGroupエンティティとのFK関係を持つOrgエンティティがあります。Springデータページオブジェクトjson応答が参照オブジェクト情報を持たない

@Entity 
@Access(AccessType.FIELD) 
@Table(uniqueConstraints = @UniqueConstraint(columnNames={"appName","appId"})) 
public class Org { 

    @Id 
    @Column(name = "Id") 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 

    private int Id; 

    /*@GenericGenerator(name = "sequence_org_id", strategy = "com.ciphercloud.ae.generators.OrgIdGenerator") 
    @GeneratedValue(generator = "sequence_org_id") 
    @Column(name="Org_Id") 
    private String orgId;*/ 

    @NotEmpty (message = "org username is mandatory") 
    private String username; 

    @NotEmpty (message = "org password is mandatory") 
    private String password; 

    private String securityToken; 

    @GenericGenerator(name = "sequence_app_id", strategy = "com.ciphercloud.ae.generators.AppIdGenerator") 
    private String appName; 

    private String appId; 

    @NotBlank (message = "Org Category should not be null or empty") 
    private String orgCategory; 

    private String orgSubCategory; 

    @NotBlank (message = "org regionId should not be null or empty") 
    private String regionId; 

    @Transient 
    private int parent_org_id; 


    @NotFound(action = NotFoundAction.IGNORE) 
    @ManyToOne 
    @JsonIgnore 
    @JoinColumn(name = "parent_org_id") 
    private Org org; 

    @NotBlank (message = "Org Type should not be null or empty") 
    private String orgType; 

    @Transient 
    private int ownergroup_id; 

@ManyToOne (cascade = CascadeType.ALL) 
    @JoinColumn(name = "ownergroup_id") 
    private OwnerGroup ownerGroup; 

私のリポジトリクラスは、以下のようになります私は、RESTとして公開するためのコントローラクラスを持っていると私は残りのクライアントでの要求をテストする際にコードが今のように

@RequestMapping(value = "/search", method = RequestMethod.GET) 
    public ResponseEntity<List<Org>> testmap(@RequestParam MultiValueMap<String, String> params) { 

     System.out.println("params........" + params); 

     List<Org> orgs = orgServiceImpl.search(params); 
     if (orgs == null || orgs.size()==0) { 
      throw new ResourceNotFoundException("Invalid search criteria "); 
     } else { 
      return new ResponseEntity<List<Org>>(orgs, HttpStatus.OK); 
     } 
    } 


@RequestMapping(value = "/filter/{pageNumber}", method = RequestMethod.GET) 
    public ResponseEntity<PagedResources<org.springframework.hateoas.Resource<Org>>> filter(@PathVariable Integer pageNumber, @RequestParam HashMap<String, List<String>> params) { 

     System.out.println("params........" + params); 

     if(pageNumber <= 0){ 
      pageNumber = 1; 
     } 

     Page<Org> orgs = orgServiceImpl.filter(pageNumber, params); 
     if (orgs == null || orgs.getSize()==0) { 
      throw new ResourceNotFoundException("Invalid filter criteria "); 
     } else { 
      return new ResponseEntity<>(pagedResourceAssembler.toResource(orgs), HttpStatus.OK); 
     } 
    } 

ある

public interface OrgRepostiory extends JpaRepository<Org, Serializable> { 
    public List<Org> findByOrgType(@Param("orgtype") String orgType); 
    public Page<Org> findByOrgTypeIn(@Param("orgtype") List<String> orgType, Pageable pageable); 
} 

request = > http://localhost:8080/orgs/filter/1?orgtype=Production 

次の出力を得ています。改ページ

request => http://localhost:8080/orgs/search?orgtype=Production 

// response 
{ 
username: "testdemo8" 
password: "testpwd1" 
securityToken: "testkey1" 
appName: null 
appId: null 
orgCategory: "Admin" 
orgSubCategory: null 
regionId: "na15" 
parent_org_id: 0 
available: true 
inductionStatus: null 
orgType: "Production" 
ownergroup_id: 0 
**ownerGroup: { 
name: "sfdc-ft" 
description: "4.5 release" 
id: 1 
}-** 
id: 32 
active: false 
} 
ページオブジェクトが使用されていない我々が観察する場合

、その子テーブルのデータを返さず

// response 
{ 
username: "testdemo8" 
password: "testpwd1" 
securityToken: "testkey1" 
appName: null 
appId: null 
orgCategory: "Admin" 
orgSubCategory: null 
regionId: "na15" 
parent_org_id: 0 
available: true 
inductionStatus: null 
orgType: "Production" 
ownergroup_id: 0 
id: 32 
active: false 
}- 
- 
}- 
_links: { 
self: { 
href: "http://localhost:8080/orgs/filter/1?orgtype=Production" 
}- 
} 

ただし、ページネーションを使用すると、子テーブルのデータが返されません。

ページングを使用する場合、子テーブル情報を取得するために追加する必要がありますか?

+0

いずれかの回答がありますか? –

答えて

0

問題をデバッグし、コントローラクラスで使用しているpagedResourceAssemblerクラスによって結合データがトリミングされていることがわかりました。私は

リターン新しいResponseEntity>(組織、HttpStatus.OK)

は今だけでなく、その取得参照オブジェクトデータは予想通りで置き換えます。

関連する問題