1.2.4 JPA.em().createNativeQuery(queryString).getResultList() ERROR!!!!

4,005 views
Skip to first unread message

Ferreira

unread,
Mar 15, 2012, 3:23:12 PM3/15/12
to play-fr...@googlegroups.com
Hi, can some one tell me why this doen't work?
thanks in advance

this works fine but is to much information

String queryString="SELECT FROM User as u INNER JOIN Skill as sk";
 
List<Object[]> list = JPA.em().createNativeQuery(queryString).getResultList();


but when i try to get just from a user, it doesn't work

Execution exception

PersistenceException occured : org.hibernate.exception.SQLGrammarException: could not execute query

String queryString ="SELECT uhs.*, sk.* FROM UserHasSkills uhs"+
"LEFT JOIN User us ON us.id = uhs.id"+
"LEFT JOIN skill sk ON sk.id = uhs.skill_id"+
"WHERE uhs.user_id=1";

List<Object[]> list = JPA.em().createNativeQuery(queryString).getResultList();
 

Stikkos

unread,
Mar 15, 2012, 3:41:11 PM3/15/12
to play-fr...@googlegroups.com
Do you have a property called skill_id or user_id in the UserHasSkills entity? Or are these the name of the database column?
In your query you need to use the entity parameter names (and not the DB column names).


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/OAXtSiHfWDkJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Stikkos

unread,
Mar 15, 2012, 3:42:44 PM3/15/12
to play-fr...@googlegroups.com
Sorry, just noticed that you are calling createNativeQuery so ignore my last comment.

can you execute the query directly in a SQL client?

Nicolas Leroux

unread,
Mar 15, 2012, 3:46:07 PM3/15/12
to play-fr...@googlegroups.com
You are missing white space between your strings. It should be:


String queryString ="SELECT uhs.*, sk.* FROM UserHasSkills uhs "+
"LEFT JOIN User us ON us.id = uhs.id "+
"LEFT JOIN skill sk ON sk.id = uhs.skill_id "+"WHERE uhs.user_id=1";



Ferreira

unread,
Mar 15, 2012, 4:16:06 PM3/15/12
to play-fr...@googlegroups.com
Thanks every one
Reply all
Reply to author
Forward
0 new messages