Total members 11893 |It is currently Tue Nov 05, 2024 12:37 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Hi,

I have defined a Native query in my entity class as below

Code:
@NamedNativeQuery(name="Customer.findByaccountNo",
      query="SELECT TO_CHAR(TIME_STAMP,'DDMONYYYY:HH24MISS') TIME_STAMP," +
            "MERCH_NBR, FDB_SEQ_NBR, OWNER_IIC, ACQUIRER, CHARGE_AMT," +
            "TO_CHAR(CHARGE_DATE,'DDMONYYYY:HH24MISS') CHARGE_DATE, " +
            "CHARGE_CURRENCY, MERCH_NAME, CITY, GEOCODE, INTES," +
            "CHARGE_TYPE, TYPE_OF_CHARGE, REFERENCE_NBR, DATE_TYPE," +
            "APPROVAL_CODE, AUTH_NBR, FUNCTION_CODE, BILLING_CCY, BILLING_AMT, DOLLAR_AMT," +
            "RECAP_ID, RECAP_DET_SEQ, DISPOSITION, AMT_WRITE_OFF, AMT_MERCH_CHRG, AMT_CUST_CHRG, AMT_RECOVERED," +
            "FRAUD_STATUS, TXN_SOURCE, METHOD_OF_ENTRY " +
            "FROM MYDB.CUSTOMER " +
            "WHERE ACCOUNT_NBR = ? AND CHARGE_DATE >= ? AND CHARGE_DATE <= ? ORDER BY TIME_STAMP",
            resultClass=Customer.class),


in my DAO i am using as below

Code:

Query query = this.entityManager.createNativeQuery("Customer.findByaccountNo", Customer.class);
query.setParameter(1, accountNbr);
query.setParameter(2, chargeDateFrom);
query.setParameter(2, chargeDateTo);
return query.getResultList();



Below is the exception trace i got....

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1315)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255)
at com.dcisc.gui.gfd.persistence.dao.FdbFraudTranDataDAO.getFraudDataByAcct(FdbFraudTranDataDAO.java:80)
at com.dcisc.gui.gfd.persistence.entity.FdbFraudTranDataIntegrationTest.testGetFraudDataByAcct2(FdbFraudTranDataIntegrationTest.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)




Author:

Dear jaggsmca325 ,
I notice that the query is written in a complex way ? , you should put it thins why ? Does the exception log ended on the above part ?

i have doubts about this part .
query.setParameter(2, chargeDateTo);

i think it should be
query.setParameter(3, chargeDateTo);


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : @NamedNativeQuery:SQLGrammarException could not execute quer
 execute if else simultaneously     -  
 Execute System Commands     -  
 calculating time required to execute function     -  



Topic Tags

Java JPA






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com