File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes JPA Native Query problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JPA Native Query problem" Watch "JPA Native Query problem" New topic

JPA Native Query problem

Mohammad wish

Joined: Oct 11, 2011
Posts: 12
Dear Professionals,
I have a native sql query as the following :

for(init i=0; i <=2 ; i++){
String sql = "Select * from accounts where id = ?";
Query query = em.createNativeQuery(sql,AccountBean.class);
query.setParameter(1, i );

AccountBean accountBean = (AccountBean)query.getSingleResult();

for the first loop it works correct but any loop after the first one return the same result to the first one , i debug it, the parameter changed , it works correct if i changed

Query query = em.createNativeQuery(sql,AccountBean.class);


Query query = em.createNativeQuery(queryString);

I agree. Here's the link:
subject: JPA Native Query problem
Similar Threads
Data truncation: Truncated incorrect DOUBLE value:
Issue calling MYSQL Stored Proc using Hibernate JPA
@OneToMany return objects with the same reference
Native query always returning same data
Bulk Update with native SQL