当我通过投影获取数据时,我有以下课程ReportReview
,它为我提供了以下数据但我还希望通过报告审核获取ratedProperty
课程中PropertyRating
的数据,当我使用这个投影它给我以下回应
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": "student@gmail.com",
"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 :(得分:0)
@JoinColumn(name="ratedProperty")
@ManyToOne (cascade = CascadeType.REMOVE, targetEntity = Property.class, fetch = FetchType.EAGER)
private Property ratedProperty;