我正在使用Spring-Data-Solr,我有三个表并尝试从这些表中获取所有数据。这是表格的关系:
车牌表:
ID, NAME, PRICE, DISTRICT_ID(FK), CITY_ID(FK)
地区表:
ID(PK), DISTRICT_NAME
城市表:
ID(PK), CITY_NAME
在data-config.xml中的我尝试使用sql获取Car表中的所有数据和记录:
<dataConfig>
<dataSource driver="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:/temp/example/ex" user="sa" />
<document>
<entity name="city" query="select * from city">
<field column="id" name="city_id" />
<field column="name" name="city_name" />
<entity name="cars" query="select * from cars where city_id='${city.id}'">
<field column="id" name="id" />
<field column="name" name="name" />
<entity name="district" query="select * from district where id = '${cars.district_id}'">
<field column="id" name="district_id" />
<field column="name" name="district_name" />
</entity>
</entity>
</entity>
</document>
当我在Solr Admin上执行时,我刚收到2条记录,尽管在我的汽车表中有11条记录。
如何获得Car table中的所有(11条记录)?感谢
答案 0 :(得分:0)
<dataConfig>
<dataSource driver="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:/temp/example/ex" user="sa" />
<document>
<entity name="city" query="select City.city_id ,City.city_name ,car.id ,car.name ,District.id from Car join City on city.id = car.CITY_ID join District on car.DISTRICT_ID = District.id ">
<field column="cityid" name="City.city_id" />
<field column="cityname" name="City.city_name" />
<field column="carid" name="car.id" />
<field column="carname" name="car.name" />
<field column="Districtid" name="District.id" />
<etc... any column you need>
</entity>
</document>
修改强>
或者您可以在视图中执行查询[ TempView ] AND配置
<entity name="city" query="select * from TempView ">
<field column="cityid" name="City.city_id" />
<field column="cityname" name="City.city_name" />
<field column="carid" name="car.id" />
<field column="carname" name="car.name" />
<field column="Districtid" name="District.id" />
<etc... any column you need>
</entity>
</document>