2017-06-02 23 views
0

我有以下類ReportReview當我用投影得到數據時,它給了我下面的數據但是我也想在PropertyRating類中得到ratedProperty的數據與報告複習,當我使用這個投影它給我下面的響應如何在彈簧中使用投影獲取數據

ReportReview.class

private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    private Long id; 

    @ManyToOne 
    private User repoter; 

    @ManyToOne 
    private PropertyRating reportedReview; 

    // @OneToOne(mappedBy="PropertyRating",targetEntity=PropertyRating.class) 
    //private Property propertyRating; 


    @Column(length=1024) 
    private String Report; 

    public Long getId() { 
     return id; 
    } 

    public void setId(Long id) { 
     this.id = id; 
    } 
     .... Getters and Setters 
    } 

PropertyRating.class

@EntityListeners(AuditingEntityListener.class) 
public class PropertyRating implements PropertyRatingGetters{ 


    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id; 

    @JsonDeserialize(using = CustomDateDeserializer.class) 
    @JsonSerialize(using = CustomDateSerializer.class) 
    private Date createdDate; 

    @JsonDeserialize(using = CustomDateDeserializer.class) 
    @JsonSerialize(using = CustomDateSerializer.class) 
    private Date modifiedDate; 

    @JoinColumn(name="rater") 
    @CreatedBy 
    @ManyToOne 
    private User rater; 

    @JoinColumn(name="ratedProperty") 
    @ManyToOne (cascade = CascadeType.REMOVE, targetEntity = Property.class) 
    private Property ratedProperty; 

    private float rating; 


    @Column(length=1024) 
    private String reviewText; 

..getter and setter 
} 

投影

@Projection(name="PropertyWithReportReview", types=ReportReview.class) 
public interface PropertyWithReportReview extends ReportReviewGetter { 

} 

reportReviewGetter

public interface ReportReviewGetter { 

     Long getId(); 
     User getRepoter(); 
     PropertyRating getReportedReview(); 
     String getReport(); 
    } 

**Response I get** 
"reportReviews": [ 
     { 
     "id": 1, 
     "report": "abc", 
     "repoter": { 
      "id": 2, 
      "logonEmail": "[email protected]", 
      "name": "Student", 
      "emailVerified": true, 
      "address": "A-213", 
      "postcode": "888", 
      "phoneNo": "2342", 
      "passportNo": null, 
      "description": null, 
      "meanRating": 2 
     }, 
     "reportedReview": { 
      "id": 1, 
      "createdDate": null, 
      "modifiedDate": null, 
      "rating": 3, 
      "reviewText": "gfhdvfb" 
     }, 
     "_links": { 
      "self": { 
      "href": "http://localhost:8555/api/reportReviews/1" 
      }, 
      "reportReview": { 
      "href": "http://localhost:8555/api/reportReviews/1{?projection}", 
      "templated": true 
      }, 
      "repoter": { 
      "href": "http://localhost:8555/api/reportReviews/1/repoter" 
      }, 
      "reportedReview": { 
      "href": "http://localhost:8555/api/reportReviews/1/reportedReview" 
      } 
     } 
     } 
    ] 
    }, 

EDITED Property.class

public class Property implements PropertyGetters, Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id; 

    @ManyToOne(fetch = FetchType.EAGER, targetEntity = User.class) 
    private User owner; 

    @OneToMany(fetch=FetchType.LAZY,targetEntity=UniversityDistance.class,mappedBy="property") 
    private List<UniversityDistance> universityDistances; 

    @OneToMany(fetch=FetchType.LAZY,targetEntity=Room.class, mappedBy="property") 
    private Set<Room> rooms; 


    @JsonIgnore 
    @OneToMany(mappedBy="property",targetEntity=PropertyPhoto.class) 
    private List<PropertyPhoto> photos ; 

// @ManyToMany(fetch = FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.MERGE}) 
//// @JoinTable(name = "tbu1213", joinColumns = { @JoinColumn(name = "businessid", referencedColumnName = "businessid") }, inverseJoinColumns = @JoinColumn(name = "userid")) 
// @org.hibernate.annotations.LazyCollection(
//   org.hibernate.annotations.LazyCollectionOption.EXTRA 
// ) 
// private Set<UniversityDistance> universityDistances = new HashSet<UniversityDistance>(); 
//  

    @Enumerated(EnumType.STRING) 
    private PropertyType propertyType; 

    @Enumerated(EnumType.STRING) 
    private ContractType contractType; 

    private String propertyTitle; 

    @Enumerated(EnumType.STRING) 
    private PropertyStatus propertyStatus; 

    private String address; 
    @ManyToOne 
    private City city; 

    @Column(length=1000) 
    private String description; 

    private Double latitude; 
    private Double longitude; 
    private boolean wifi; 
    private boolean kitchenAppliances; 
    private boolean laundry; 
    private boolean heating; 
    private boolean cable; 
    private boolean furnished; 
    private boolean gasBill; 
    private boolean hydroBill; 
    private boolean cooling; 
    private boolean parking; 
    private boolean waterBill; 



    private boolean cctv; 
    private boolean maintenance; 
    private boolean secureEntry; 
    private boolean petAllowed; 
    private boolean smokingAllowed; 
    private boolean guestAllowed; 


    private int noOfRoom; 

    @JsonIgnore 
    private float meanRating; 


    @ManyToOne() 
    private Business business; 
    } 

回答

0
@JoinColumn(name="ratedProperty") 
    @ManyToOne (cascade = CascadeType.REMOVE, targetEntity = Property.class, fetch = FetchType.EAGER) 
    private Property ratedProperty; 
+0

我在哪裏添加這個? – SFAH

+0

這與您在「PropertyRating」類中具有的相同字段。我jave增加了'fetch = FetchType.EAGER' – pvpkiran

+0

什麼都沒發生: – SFAH

相關問題