2015-01-13 266 views
0

當我們通過setParameter設置marketOfferId的值時,它不會返回結果。但是,當我用查詢中的單引號將實際值:marketOfferId替換爲「BDEN3F」時。有人可以幫我嗎是什麼原因?JPA命名查詢未返回結果

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) 

回答

0

我已經從TypedQuery更改爲查詢解決了這個問題。查詢查詢= em.createNamedQuery(namedQuery,MarketingOfferWEB.class).setParameter(「marketOfferId」,iden);