Compass的SearchableReference
Class Entry
@Searchable(alias="entry")
{
@SearchableId
String id...}
@Searchable(alias="comment")
Class Comment
{@SearchableId
String id
...
@SearchableReference(refAlias="entry")
private Entry entry;
}
如上,按照我的理解,当检索到一个Comment对象时,Compass会把这条Comment对应的Entry也取出来。因为在SearchableReference的doc中有这么一句
A searchable reference is a class field/property that reference another class, and the relationship need to be stored by Compass so it can be traversed when getting the class from the index.
然而,当我用Compass为数据库建立索引时,收到一个异常
cannot marshall a null id
但是通过cpm.xml文件配置,建立索引,检索都没有问题,配置文件如下,难道被我发现了一个bug? :o
//Entry.cpm.xml
<?xml version="1.0"?>
<!DOCTYPE compass-core-mapping PUBLIC
"-//Compass/Compass Core Mapping DTD 1.0//EN"
"http://www.opensymphony.com/compass/dtd/compass-core-mapping.dtd">
<compass-core-mapping package="xxx.xxx.pojos">
<class name="Entry" alias="entry">
<id name="id" />
...
<property name="title">
<meta-data>title</meta-data>
</property>
<property name="content">
<meta-data>content</meta-data>
</property>
</class>
</compass-core-mapping>
//Comment.cpm.xml
<?xml version="1.0"?>
<!DOCTYPE compass-core-mapping PUBLIC
"-//Compass/Compass Core Mapping DTD 1.0//EN"
"http://www.opensymphony.com/compass/dtd/compass-core-mapping.dtd">
<compass-core-mapping package="com.gln.bloger.pojos">
<class name="Comment" alias="comment">
<id name="id" />
...
<property name="content">
<meta-data>content</meta-data>
</property>
<reference name="entry"/>
</class>
</compass-core-mapping>
错误我也遇到了, 不过是我在创建实时索引的时候碰到的 我用iBATIS 添加一个产品后返回该产品id 赋值给产品在用compass的session.save()就成功了
至于reference 我到没有出现异常、只是关联的类取不到值。。。 不知道楼主可解决没有
楼主解决这问题没有?我也遇到这个问题了,盼赐教。
晕,搜问题搜到自己这里了。。。 :lol: