【问题标题】:SearchAPI and Hibernate unexpected end of subtreeSearchAPI 和 Hibernate 意外结束子树
【发布时间】:2013-02-28 07:52:04
【问题描述】:

我有以下实体

@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

【问题讨论】:

  • 好问题。 :) 欢迎。

标签: java hibernate google-search-api


【解决方案1】:

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

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

谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-21
    • 2010-12-27
    • 1970-01-01
    • 2011-01-05
    • 2014-03-27
    • 1970-01-01
    • 2011-06-03
    • 2019-12-25
    相关资源
    最近更新 更多