- mysql 5.1
- hibernate 4.3
- spring 4
- glassfish 4
i have written application using spring , hibernate. gives following error.
error: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'from account accountno = '123'' @ line 1
warning: standardwrappervalve[dispatcher]: servlet.service() servlet dispatcher threw exception
com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'from account accountno = '123'' @ line 1
i think there no issue hql statement.
method inside @repository
public account getaccountbyno(string accountno) { account acc = null; query query = getsession().createsqlquery(" account accountno = :accno "); query.setstring("accno", accountno); list list = query.list(); if(!list.isempty()){ acc = (account)list.get(0); } return acc; } @entity public class account implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.auto) private long id; @column(name = "accountno", nullable = false) private string accountno; @column(name = "amount", nullable = false) private double amount; @onetoone private accholder accholder; }
you not create hql query. create sql-query:
query query = getsession().createsqlquery(" account accountno = :accno ");
change to
query query = getsession().createquery(" account a.accountno = :accno ");