2013-02-28 40 views
3

意外結束我下面的實體SearchAPI和Hibernate子樹

@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; 

} 

我使用搜索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和3.5.6冬眠,最終

+0

不錯的問題。 :)歡迎。 – L0j1k 2013-02-28 07:52:52

回答

0

我覺得這裏的問題也許在於genericdao框架無法處理@ElementCollection情況。我以前沒有想過這個案例。感謝您提出。也許我可以在未來的版本中將它添加到框架中。

與此同時,編寫您的方法使用原生Hibernate查詢。您可以使用getSession()直接在DAO中獲得Hibernate會話。當你得到它的工作時,請使用能夠正常工作的HQL查詢來更新這個線程。我可以用它來找出一種方法在框架中構建功能。

謝謝。