0
我在使用和mapping.TableToResourceMapping
設置@SearchableComponent對象時遇到問題。ResultSetJdbcGpsDevice&@SearchableComponent
試圖測試,我設置了兩個表映射爲對象(忽略ID的事情,除非這實際上是導致此問題):
a
id (pk) | name | create_time | update_time
------------------------------------------
b
id (pk|fk) | property1 | property2 | property3
----------------------------------------------
A和B的定義是這樣的:
@Searchable(root=true)
public class A {
@SearchableId
private int id;
@SearchableProperty
private String name;
@SearchableProperty
private long create_time;
@SearchableProperty
private long update_time;
@SearchableComponent
private B b;
// getters, setters
}
@Searchable(root=false)
public class B {
@SearchableId
private int id;
@SearchableProperty
private String property1;
@SearchableProperty
private long property2;
@SearchableProperty
private String property3;
// getters, setters
}
下面是我如何設置的一切行動:
conf = new CompassConfiguration()
.setSetting(CompassEnvironment.CONNECTION, "target/index")
.addClass(A.class)
.addClass(B.class);
compass = conf.buildCompass();
ResultSetJdbcGpsDevice jdbc = new ResultSetJdbcGpsDevice();
jdbc.setDataSource(ds);
jdbc.setName("sql-device");
jdbc.setMirrorDataChanges(true);
TableToResourceMapping mappingA = new TabbleToResourceMapping("a", "A");
mapping.addIdMapping(new IdColumnToPropertyMapping("id", "id"));
mapping.addDataMapping(new DataColumnToPropertyMapping("name", "name"));
mapping.addDataMapping(new DataColumnToPropertyMapping("create_time", "create_time"));
mapping.addDataMapping(new DataColumnToPropertyMapping("update_time", "update_time"));
TableToResourceMapping mappingB = new TabbleToResourceMapping("b", "B");
mapping.addIdMapping(new IdColumnToPropertyMapping("id", "id"));
mapping.addDataMapping(new DataColumnToPropertyMapping("property1", "property1"));
mapping.addDataMapping(new DataColumnToPropertyMapping("property2", "property2"));
mapping.addDataMapping(new DataColumnToPropertyMapping("property3", "property3"));
jdbc.addMapping(mappingA);
jdbc.addMapping(mappingB);
gps = new SingleCompassGps(compass);
gps.addGpsDevice(jdbc);
gps.start();
gps.index();
有了這個,我得到以下錯誤,從指南針:
java.lang.IllegalStateException: {sql-device}: No resource mapping defined in gps mirror compass for alias [B]. Did you defined a jdbc mapping builder?
at org.compass.gps.device.jdbc.ResultSetJdbcGpsDevice.doStart(ResultSetJdbcGpsDevice.java:127)
at org.compass.gps.device.AbstractGpsDevice.start(AbstractGpsDevice.java:124
at org.compass.gps.impl.AbstractCompassGps.start(AbstractCompassGps.java:166)
...
如果我集B爲root=true
它工作正常,我可以在A和B字段搜索文本和得到的東西回來。但是,當A被構建並通過搜索返回時,其B實例是空的。
如果我搜索property2:0
然後我檢索B的實例映射到該列爲0的行,但我也檢索A的每個實例 - 因爲它們的所有B組件都是默認實例。
我該如何正確設置它?我覺得我可能會錯過Compass文檔中的一些東西。