cianBuckley
cianBuckley

Reputation: 1284

hibernate throwing: An unexpected token "" was found following ""

I have a native SQL query that i want to run through hibernate, but throws an error:

org.hibernate.exception.SQLGrammarException:
could not execute native bulk manipulation query
Caused by: 
com.ibm.db2.jcc.am.SqlSyntaxErrorException: An unexpected token ""
was found following "".  Expected tokens may include:  "NQ_EXE_ID = 12345"

the code i run to perform update is:

SQLQuery updateQuery = getSession().createSQLQuery(updateSql);
System.out.println(updateQuery.getQueryString());    
updateQuery.executeUpdate();

during debug i can see inside the SQLQuery object and the sql is: (which runs fine in db2)

UPDATE some_table SET DEST_FLDR = 'some_value' ,
LST_CHG_TMS = CURRENT TIMESTAMP
WHERE SUB_RUN_ID = 111111    
AND INQ_EXE_ID = 12345   ;

if i manually run the sql produced by the code above, it will execute fine. However when i try to do it through hibernate it throws the 'syntaxErrorException'. Any ideas? Thanks

Upvotes: 4

Views: 4212

Answers (1)

JB Nizet
JB Nizet

Reputation: 691963

The problem is caused by the semicolon at the end of the query. The PostgreSQL SQL tool you use wants it because it allows separating multiple queries, but to execute individual queries via a Java statement, the semi-colon must not be there.

Upvotes: 7

Related Questions