Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

java - Calling an oracle function from JPA

I am trying to call a simple function from a JPA class that returns a number based on some calculations and has the following definition.

'CREATE OR REPLACE FUNCTION CFB.FC_AMOUNT_CHECK(accountNumber IN VARCHAR2)
return NUMBER IS .....'

I am trying to call this function from JPA the following way.

StringBuilder sql = new StringBuilder("call CFB.FC_AMOUNT_CHECK(:accountNumber)");
Query query = em.createNativeQuery(sql.toString());
query.setParameter(1, '1234');
List<?> result = query.getResultList();

....

However, when I execute this class, I get the below exception all the time:

java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [1]

I cant seem to get how JPA cannot find parameter 1....I have been breaking my head with this for the last 4 hours. Can anyone please suggest how to get the result I want?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are looking to call a function in JPA select query then follow below link, it works:

http://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/j_func.htm


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...