执行HQL查询时出现org.hibernate.queryexception错误

时间:2013-12-18 07:08:24

标签: java hibernate db2 hql rank

我正在HQL中执行查询,我收到以下错误。我使用 DB2 作为数据库,

Error: Caused by:  org.hibernate.queryexception: in expected  [hql query]

和查询是,

final String qStr = "select distinct a.* from (select attr.* from AttributeModel attr, BOModel bo, BusinessIdentifierModel ident, NameTransferModel name, NameTransferModel name2 WHERE" +
                                    "bo.businessIdentifierId = ident.businessIdentifierId AND" +
                                    "ident.businessIdentifier = :businessIdentifier AND" +
                                    "attr.compAttributeModelKey.boRowNo = bo.compBOModelKey.boRowNo AND" +
                                    "attr.compAttributeModelKey.eventId = bo.compBOModelKey.eventId AND" +
                                    "bo.typeId = name.nameTransferId AND" +
                                    "name.originalName = :className AND" +
                                    "bo.nameId = name2.nameTransferId AND" +
                                    "name2.originalName = :fieldName) a JOIN (SELECT event.eventId, attr2.nameTransferId, attr2.compAttributeModelKey.boRowNo, RANK() OVER (PARTITION BY bo2.businessIdentifierId, attr2.nameTransferId, attr2.compAttributeModelKey.boRowNo ORDER BY event.eventId desc ) rank from EventModel event, BOModel bo2, AttributeModel attr2,BusinessIdentifierModel ident  WHERE" +
                                                                        "event.changeTime <= :time AND" +
                                                                        "bo2.businessIdentifierId = ident.businessIdentifierId AND"+
                                                                        "bo2.compBOModelKey.eventId = event.eventId AND" +
                                                                        "attr2.compAttributeModelKey.eventId = event.eventId AND" +
                                                                        "attr2.compAttributeModelKey.boRowNo = bo2.compBOModelKey.boRowNo AND" +
                                                                        "ident.businessIdentifier = :businessIdentifier) b ON (" +
                                                                        "a.eventId = b.eventId AND" +
                                                                        "a.nameTransferId = b.nameTransferId AND" +
                                                                        "a.boRowNo = b.boRowNo AND" +
                                                                        "RANK = '1')";

请一瞥并建议我是否有任何错误的语法

1 个答案:

答案 0 :(得分:0)

(第一个)错误实际上在消息中......

Error: Caused by:  org.hibernate.queryexception: **in** expected  [hql query]

预计IN。

我真的不明白你的加入。 你在第二个subselect上的JOIN,应该是IN?