How to get data from multi table in data-config of Solr

219
February 28, 2017, at 4:44 PM

I'm using Spring-Data-Solr, I have three tables and try get all data from those tables. this is relationship of table:

Car table:

      ID, NAME, PRICE, DISTRICT_ID(FK), CITY_ID(FK)

District table:

      ID(PK), DISTRICT_NAME

City table:

      ID(PK), CITY_NAME

in data-config.xml I try get all data and records in Car table with sql following as:

<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>

When I execute on Solr Admin I just received 2 records, although in my car table have 11 records.

How to get all(11 records) in Car table? thanks

Answer 1
<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>
READ ALSO
Representing numbers without casting in Java

Representing numbers without casting in Java

Does a more natural way to represent those numbers without the use of casting exist in Java?

303
Lazily initialize a collection in Hibernate

Lazily initialize a collection in Hibernate

In my managed bean I have a code as following :

351
Is there any way to communicate mysql to JAVA

Is there any way to communicate mysql to JAVA

Is there any way to communicate mysql to JAVA

191
Automation framework

Automation framework

Im developing an automation frameworkI have been asked to create a java class and a method in it automatically by giving inputs through wrapper class

355