JPA命名查询未返回结果

时间:2015-01-13 06:49:29

标签: hibernate jpa

当我们将marketOfferId的值设置为setParameter时,它不会返回结果。但是当我用查询中的单引号将:marketOfferId替换为实际值时,它正在运行' BDEN3F'。有人可以帮我解释是什么原因吗?

String iden = "BDEN3F";
TypedQuery query = em.createNamedQuery(namedQuery,MarketingOfferWEB.class).setParameter("marketOfferId",iden);

- 不工作

@NamedNativeQuery(name = MarketingOfferWEB.FIND_WEB_MARKETOFFER, query = "SELECT * FROM VW_WEB_MKT_OFFERS WHERE MKT_OFFER_UID = :marketOfferId AND TENANT_ID=1", resultClass = MarketingOfferWEB.class)

- 工作

@NamedNativeQuery(name = MarketingOfferWEB.FIND_WEB_MARKETOFFER, query = "SELECT * FROM VW_WEB_MKT_OFFERS WHERE MKT_OFFER_UID = 'BDEN3F' AND TENANT_ID=1", resultClass = MarketingOfferWEB.class)

1 个答案:

答案 0 :(得分:0)

我已经通过从TypedQuery更改为Query来解决了这个问题。

查询query = em.createNamedQuery(namedQuery,MarketingOfferWEB.class).setParameter(“marketOfferId”,iden);