Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue calling MYSQL Stored Proc using Hibernate JPA

 
sarv ram
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe it is a typo?
getEmpolyee

Isn't it getEmployee?
 
sarv ram
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishal,

Thanks for the useful suggestion, I have formatted the content now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic