File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Issue calling MYSQL Stored Proc using Hibernate JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Issue calling MYSQL Stored Proc using Hibernate JPA" Watch "Issue calling MYSQL Stored Proc using Hibernate JPA" New topic
Author

Issue calling MYSQL Stored Proc using Hibernate JPA

sarv ram
Greenhorn

Joined: Mar 17, 2009
Posts: 3

ORM: Hibernate
ORM Mapping: JPA
Database: MySQL
Issue: MySQLSyntaxErrorException on calling Stored Procedure


I am having issue in calling MYSQL Stored Procedure from a Hibernate JPA application.

I am calling the procedure as given below:



The Stored Procedure is running fine in MySQL Querybrowser but when I call from application the following error is thrown:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 2' at line 1

Any one has idea please help.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Maybe it is a typo?
getEmpolyee

Isn't it getEmployee?


OCUP UML fundamental and ITIL foundation
youtube channel
sarv ram
Greenhorn

Joined: Mar 17, 2009
Posts: 3
Yes, when I changed the original code to post it on the forum, I did typo mistake.

Now I have modified the code in the above query.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Hello Sarv,

Welcome to JavaRanch!

--- Code
String queryStr = "{Call getEmpolyee(?)}";
Query queryUser = em.createNativeQuery(queryStr, Empolyee.class).setHint("org.hibernate.callable","true").setHint("org.hibernate.readOnly","true");

queryUser.setParameter(1, userName);
Empolyee empolyee= (UserInfo) queryUser.getSingleResult();
Code --

You can use code tags to enclose your code. Refer http://faq.javaranch.com/java/UseCodeTags which makes your post clearer.
yes, when I changed the original code to post it on the forum, I did typo mistake.

And refer this. http://faq.javaranch.com/java/PostRealCode to avoid this kind of confusions.
sarv ram
Greenhorn

Joined: Mar 17, 2009
Posts: 3
Hi Vishal,

Thanks for the useful suggestion, I have formatted the content now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue calling MYSQL Stored Proc using Hibernate JPA