SearchAPI和Hibernate意外结束了子树

时间:2013-02-28 07:52:04

标签: java hibernate google-search-api

我有以下实体

@Entity
public class Task {

private List<TaskParameter> taskParameters = Collections.emptyList();

@ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "taskParameters", joinColumns = @JoinColumn(
            name = "task_id"))
    public List<TaskParameter> getTaskParameters() {
        return taskParameters;
    }

}

并且TaskParameter实体是一个可嵌入的定义如下:

@Embeddable
public class TaskParameter {
        private String name;
    private String value;

}

我正在使用Search API这种方法

@Transactional(readOnly = true) 
public List<Task> getTaskByRequisitionId(String requisitionId) {
    List<Task> tasks;
    Search search = new Search();
    search.addFilterAll("taskParameters",Filter.equal("value", requisitionId));
    tasks = taskDao.search(search);
    return tasks;
}

但获得例外

[INFO] 2013-02-28 10:20:06,641 [btpool0-14] ERROR org.hibernate.hql.PARSER - <AST>:0:0: unexpected end of subtree
[INFO] 2013-02-28 10:20:06,642 [btpool0-14] ERROR org.hibernate.hql.PARSER - <AST>:0:0: expecting "from", found '<ASTNULL>'

[INFO] org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [select _it from com.planetsystems.procnet.model.jbpm.Task _it where not exists (from _it.taskParameters _it1 where not (_it1.value = :p1 and _it1.value is not null))]

我正在使用genericdao 1.1.0和hibernate 3.5.6-Final

1 个答案:

答案 0 :(得分:0)

我认为这里的问题可能是genericdao框架无法处理@ElementCollection案例。我以前没想过这个案子。谢谢你提出来。也许我可以在将来的版本中将它添加到框架中。

同时,编写您的方法以使用本机Hibernate查询。您可以使用getSession()直接在DAO中获取Hibernate会话。当它运行时,请使用能够正常工作的HQL查询更新此线程。我可以用它来找出一种在框架中构建功能的方法。

感谢。