Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Clarification regarding createNativeQuery() method

 
soma venkat
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am very new to EJB3.0.

Please let me know the difference between ? and ?1 that we will use in the query passed to createNativeQuery() method.

Thanks in advance.

Regards,
Soma
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a native query "?" means insert the parameter bound for the current index, i.e. the first ? is the first parameter, the second ? is the second parameter.

"?1" means insert the query parameter bound to 1. The only time you would use this is if you wanted to insert the same parameter twice, or wanted control over the JPA Query parameter order.

em.createNativeQuery("select salary, ?1 from emp where salary > ?1").setParameter(1, 100000).getResultList()
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!