smali
smali

Reputation: 4805

Hibernate exception Query not properly ended

Getting exception while running this query

select COUNT(tl.LOG_ID)AS EVTCOUNT,tl.PRIORITY FROM Customer_? tl Where tl.DEVICE_REPORTED_TIME >= SysDate-90 GROUP BY tl.PRIORITY ORDER BY tl.PRIORITY`

Here I am using query.setLong(0,custId);

so it will become like Customer_1

If I run the above query from SqlDeveloper IDE It is working fine or If I set this value as Statically like Customer_1 instead of Customer_? It working fine.

Errors:

WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 933, SQLState: 42000 ERROR: org.hibernate.util.JDBCExceptionReporter - ORA-00933: SQL command not properly ended

What Might be wrong with this query though other queries are running fine?

Edit

I am using NamedQueries and I have written this query in a separate xml file.

Upvotes: 0

Views: 4917

Answers (1)

Predrag Maric
Predrag Maric

Reputation: 24433

You can't use a parameter in a query like that. Without going into the logic behind this, your best option is to concatenate the query string before creating a query

String queryString = "select COUNT(tl.LOG_ID) AS EVTCOUNT,tl.PRIORITY FROM Customer_" + custId + " tl Where tl.DEVICE_REPORTED_TIME >= SysDate-90 GROUP BY tl.PRIORITY ORDER BY tl.PRIORITY";
Query query = session.createSQLQuery(queryString);

EDIT

As for NamedQueries, they are compiled when the application is started so I don't think there is a way to change the target entity (table) at runtime.

Upvotes: 3

Related Questions