FullTextQuery.setProjection(" id"," author")忽略了作者的id,name属性。我该如何检索这些属性?
@MappedSuperclass
class BaseContent{
@IndexedEmbedded(prefix = "author.", includePaths = {"id", "name"}) @ManyToOne
Author author;
}
@Entity @Indexed
class Content extends BaseContent{
@Id @DocumentId
Integer id;
}
@Entity
class Author{
@Id
Integer id;
@Field(store = Store.YES)
String name;
}
修改 这个查询是否正确?。
FullTextQuery ftq = fullTextSession.createFullTextQuery(luceneQuery, Content.class);
ftq.setProjection("id", "author.id", "author.name");
ftq.setResultTransformer(new AliasToBeanResultTransformer(Content.class));
List<Content> result = ftq.list();
答案 0 :(得分:0)
使用author.
前缀。
fullTextQuery.setProjection("author.id", "author.name")
编辑:您是否尝试在没有变压器的情况下检查结果?它应该返回带有投影内容的List<Object[]>
。如果是,那么变压器就不起作用了。我非常怀疑AliasToBeanResultTransformer
是否能够处理复合别名,例如&#34; author.name&#34;。你可能需要自己的变压器。
另请注意:
List<Content>
为您