spring boot jpa 同表子级查询求助
SunshineMan opened this issue · 3 comments
我的查询涉及的三个关键表分别是:
Garden 园区表:--》House 房源表:--》Entrust寄租寄售委托表:,由于本地的地址复杂性,我们汕头这边比如一个金涛庄,下面有金涛庄东区、金涛庄西区、然后东西区下面还有华明花园、嵩苑、信苑。这些我都放在同一个Garden表里,需求是当用户输入“金涛”字串查询时,可以将涉及到有金涛两字以及下级花园小区的房源给查出来。
三大表具体如下:
Garden 园区表:
@entity
public class Garden {
@id
private long id;
private String name;
private long fatherId;//父级ID
private long level;
private String relationPath;//后来追加了一个类似“/父级ID/自己ID/" 的路径。
@OneToMany()
@joincolumn(name = "fatherId")
private List children = new ArrayList<>();
@OneToMany()
@joincolumn(name = "garden")
private List houseList = new ArrayList<>();
House 房源表:
@entity
public class House {
@id
private long id;
private long gardenId;
private long houseType1Id;
private long room;
private double area;
<其它省略>
@JsonManagedReference
@OneToMany(mappedBy="house")
private List entrustList;
@manytoone
@joincolumn(name = "gardenId",insertable=false, updatable=false)
@JsonBackReference
private Garden garden;
Entrust寄租寄售委托表:
@entity
public class Entrust {
@id
private long id;
private long houseId;
private double totalPrice;
private long isSale;
@manytoone
@joincolumn(name = "houseId",insertable = false,updatable = false)
@JsonBackReference
private House house;