These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Using MySql : the query
PostPosted: Wed Oct 03, 2007 6:30 am 
Newbie

Joined: Wed Oct 03, 2007 6:17 am
Posts: 2
Location: Bangalore, India
HI I m firing a query like this in my code..

List list=HibernateUtil.getSessionFactory().getCurrentSession() .createQuery("from Person where firstName = :f").setString("f",fName) .list();

i am passing fName="XYZ" as input to this....

but i m getting the following error stating tht the query is gramatically wrong. Now, if i fire the same query appending the db name in the db browser window, it runs just fine.. can somebody plz help me out ??


Hibernate: select person0_.person_seq as person1_4_, person0_.version as version4_, person0_.first_name as first3_4_, person0_.middle_name as middle4_4_, person0_.last_name as last5_4_, person0_.dob as dob4_, person0_.modified_dt as modified7_4_ from myapp.myApp.person person0_ where person0_.first_name=?
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.dev.dao.PersonDao.findByName(PersonDao.java:186)
at com.dev.client.TestClient.main(TestClient.java:10)
Caused by: com.mysql.jdbc.exceptions.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 '.person person0_ where person0_.first_name='XYZ' at line 1

_________________
Problems cannot be solved at the same level of awareness that created them ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 8:17 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Is the problem the duplicated table name in from?

from myapp.myApp.person

? I don't know what could cause this. Maybe you have the table for Person entity defined wrongly?

Regards,
Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 8:57 am 
Newbie

Joined: Mon Oct 01, 2007 8:59 am
Posts: 18
Use setProperties instead of setString

List list=HibernateUtil.getSessionFactory().getCurrentSession() .createQuery("from Person where firstName = :f").setProperties("f",fName) .list();


Top
 Profile  
 
 Post subject: No tht wont help
PostPosted: Wed Oct 10, 2007 3:42 am 
Newbie

Joined: Wed Oct 03, 2007 6:17 am
Posts: 2
Location: Bangalore, India
The table is proper. The name is not duplicated. The first one is the db and the second "myApp" is the schema..

And setProperties() wont help coz its the same as setString. The only difference being tht its more generic....

_________________
Problems cannot be solved at the same level of awareness that created them ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 3:47 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
So you say, that if you run the query directly on mysql it works?

select person0_.person_seq as person1_4_, person0_.version as version4_, person0_.first_name as first3_4_, person0_.middle_name as middle4_4_, person0_.last_name as last5_4_, person0_.dob as dob4_, person0_.modified_dt as modified7_4_ from myapp.myApp.person person0_ where person0_.first_name=?

Of course change the questionmarks.

If no, try only:

select person0_.person_seq as person1_4_, person0_.version as version4_, person0_.first_name as first3_4_, person0_.middle_name as middle4_4_, person0_.last_name as last5_4_, person0_.dob as dob4_, person0_.modified_dt as modified7_4_ from myApp.person person0_ where person0_.first_name=?

Pavol


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.