Friday, March 19, 2010

Could not execute JDBC batch update; nested exception is org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update

Error:
Could not execute JDBC batch update; nested exception is org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update

WARN [btpool0-1] JDBCExceptionReporter.logExceptions(77) | SQL Error: 1064, SQLState: 42000

ERROR [btpool0-1] JDBCExceptionReporter.logExceptions(78) | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'condition=2, created_on='2010-02-15 00:00:00', description='
ERROR [btpool0-1] AbstractFlushingEventListener.performExecutions(301) | Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateTemplate$28.doInHibernate(HibernateTemplate.java:888)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:886)


Solution:
If you are using hibernate annotation in POJO's with MySQL,
in this example, we can eliminate this error by modifying the POJO.

Before the change

@Column(name = "condition", nullable = false)
private int condition;

After the change

@Column(name = "`condition`", nullable = false)
private int condition;