Reputation: 34424
i have below code snippet. It throws the exception at line 3 but query works fine managemnt studio(sql server 2005)
String query = "select * from user where userId=" + profileId
+ " and spaceName='" + spaceName + "'";
Session session = HibernateUtil.getSession();
List<PersonDetailsData> personDetailsData = new ArrayList<PersonDetailsData>(
session.createQuery(query).list()); //line 3
Here is the exception
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [select * from user where userId=216 and spaceName='DIG']
I am not able to figure out what's the problem with query when it is running fine in management sudio?
Upvotes: 0
Views: 7245
Reputation: 6158
As you are using sql query so you have to create a sql query such as
sess.createSQLQuery("SELECT * FROM CATS").list();
see the source source
Upvotes: 1
Reputation: 1852
It's native query, not hql. If you have mapped table field to class fields you need
session.createSQLQuery(query, PersonDetailsData.class).list();
or create hql type query -
select p from PersonDetailData p where p.userId = :userId and p.spaceName =:spaceName
and use parameters in query, not direct values.
Upvotes: 3