This content has been marked as final.
Show 4 replies
-
1. Re: Am I missing something about createNativeQuery?
dornus Oct 26, 2005 11:10 AM (in response to dornus)I am also trying something similar with one of my par classes and not having any luck
private MyParClass getResult(String id) { final Query q = em.createNativeQuery( "from MyParClass o " + "where myId = :id "+ "and myDate + INTERVAL 24 hour >= now() ",MyParClass.class ); q.setParameter("id", id); return (MyParClass) q.getSingleResult(); }
-
2. Re: Am I missing something about createNativeQuery?
dornus Oct 26, 2005 11:13 AM (in response to dornus)The error for the par query is
11:08:07,144 WARN [JDBCExceptionReporter] SQL Error: 1064, SQLState: 42000 11:08:07,144 ERROR [JDBCExceptionReporter] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the righ t syntax to use near 'from MyParClass o where myId = '1' and myDate + INTERVAL 2' at line 1 11:08:07,159 INFO [STDOUT] org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2150) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026) at org.hibernate.loader.Loader.list(Loader.java:2021) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:109) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1544) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:165) at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:650) at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:43)
-
3. Re: Am I missing something about createNativeQuery?
majohnst Oct 26, 2005 11:17 AM (in response to dornus)For a native query, I think you have to have a fully valid SQL statement. It looks like you may be using an HQL statement " from MyClass" when it should be "select field1, field2 from MyClass".
-
4. Re: Am I missing something about createNativeQuery?
dornus Oct 26, 2005 11:22 AM (in response to dornus)Yep, you're right!
It works now.
Thanks!