开发者

hibernate unexpected end of subtree when dealing with collection of basics

i have the following entity:

@Entity
public class AnalysisPolicy extends PersistentEntity{
    private Set nodeIds;

@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
        name="analysis_policy_nodes",
        joinColumns=@JoinColumn(name="analysis_policy_id")
)
@Column(name="node_id")
public Set<Long> getNodeIds() {
    return nodeIds;
}

}

and im trying the following JPQL query:

select p from AnalysisPolicy p where p.nodeIds is not empty

the result is something like:

10:11:16,665 DEBUG [org.hibernate.hql.ast.AST] --- SQL AST ---
 -[SELECT] QueryNode: 'SELECT'  querySpaces (AnalysisPolicy,analysis_policy_nodes)
    +-[SELECT_CLAUSE] SelectClause: '{select clause}'
    |  -[ALI开发者_StackOverflow中文版AS_REF] IdentNode: 'analysispo0_.f_id as f1_8_' {alias=p, className=com.emc.dpa.datamodel.analysis.AnalysisPolicy, tableAlias=analysispo0_}
    +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[p], fromElementByTableAlias=[analysispo0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
    |  -[FROM_FRAGMENT] FromElement: 'AnalysisPolicy analysispo0_' FromElement{explicit,collection join,not a fetch join,fetch non-lazy properties,classAlias=p,role=null,tableName=AnalysisPolicy,tableAlias=analysispo0_,origin=null,columns={,className=com.emc.dpa.datamodel.analysis.AnalysisPolicy}}
    -[WHERE] SqlNode: 'where'
       -[EXISTS] UnaryLogicOperatorNode: 'exists'
          -[SELECT] QueryNode: 'SELECT'  querySpaces (AnalysisPolicy,analysis_policy_nodes)
             +-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
             +-[FROM] FromClause: 'from' FromClause{level=2, fromElementCounter=0, fromElements=1, fromElementByClassAlias=[], fromElementByTableAlias=[nodeids1_], fromElementsByPath=[], collectionJoinFromElementsByPath=[p.nodeIds], impliedElements=[]}
             |  -[FROM_FRAGMENT] ImpliedFromElement: 'analysis_policy_nodes nodeids1_' ImpliedFromElement{implied,collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=com.emc.dpa.datamodel.analysis.AnalysisPolicy.nodeIds,tableName={none},tableAlias=nodeids1_,origin=AnalysisPolicy analysispo0_,columns={,className=null}}
             -[WHERE] SqlNode: 'WHERE'
                -[THETA_JOINS] SqlNode: '{theta joins}'
                   -[SQL_TOKEN] SqlFragment: 'analysispo0_.f_id=nodeids1_.analysis_policy_id'

10:11:16,681 DEBUG [org.hibernate.hql.ast.ErrorCounter] throwQueryException() : no errors 10:11:16,712 ERROR [org.hibernate.hql.PARSER] :0:0: unexpected end of subtree

followed by a long stack trace. i've found a similar stackoverflow issue here where the problem was that the syntax is different for collections of basic entities, so what im currently thinking is that my "is not empty" part should be replaces with something else. also, I couldn't get "is not null" to work. "size(nodeIds)>1" works but the generated SQL has an inner select which would be really bad in terms of performance.

what are my ways around this? (assuming I don't want to "upgrade" the collection to a collection of entities).


HQL documentation describes the following syntax, it also works in Hibernate's JPQL:

select p from AnalysisPolicy p where exists elements(p.nodeIds)

See also:

  • 16.10. Expressions


You can try this:

select p from AnalysisPolicy as p join p.nodeIds group by p
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜