我正在尝试使用以下HQL来使用条件API:
SELECT f FROM PotentialDonorFile f WHERE :causeParam MEMBER OF f.causesOfDeath
但是当我这样做时,我总是得到以下例外:
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected end of subtree [select generatedAlias0 from be.fgov.health.gift.action.domain.potentialdonorfile.PotentialDonorFile as generatedAlias0 where ( 1=1 ) and ( :param0 member of generatedAlias0.causesOfDeath ) order by generatedAlias0.modificationDate asc]
我的情况:
@Entity
@Table(name = "POTENTIAL_DONOR_FILE")
@SequenceGenerator(name = Domain.SEQUENCE_GENERATOR_NAME, sequenceName = "PDF_SEQUENCE")
//Domain contains the Id
public class PotentialDonorFile extends Domain {
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "CAUSES_OF_DEATH",
joinColumns = @JoinColumn(name = PDF_ID_JOIN_COLUMN_NAME))
@Column(name = "CAUSE_OF_DEATH")
@Enumerated(EnumType.STRING)
@Fetch(FetchMode.SELECT)
private List<CauseOfDeath> causesOfDeath;
}
代码:
Predicate filterCondition = cb.conjunction();
Expression<List<CauseOfDeath>> listExpression = potentialDonorFileRoot.get(PotentialDonorFile_.causesOfDeath);
filterCondition = cb.and(filterCondition, cb.isMember(CauseOfDeath.AUTHANASIA_CASE, listExpression));
cq.where(filterCondition);
使用jBoss 7.1.1
即使是HQL查询本身似乎也抛出相同的异常..刚刚找到https://hibernate.atlassian.net/browse/HHH-5209并且无法更新我的hibernate版本..有什么想法吗?
编辑: 我已经改为使用本机SQL的代码。当然,这不是一个完美的解决方案。如果有人知道解决方法,请回答..