wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes org.hibernate.exception.SQLGrammarException: could not insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org.hibernate.exception.SQLGrammarException: could not insert" Watch "org.hibernate.exception.SQLGrammarException: could not insert" New topic
Author

org.hibernate.exception.SQLGrammarException: could not insert

deepshah one
Greenhorn

Joined: Apr 17, 2014
Posts: 1
Hi guys,
I am having problem with my hibernate insert code:
Error Is Like:

org.hibernate.exception.SQLGrammarException: could not insert: [regVO.FeedbackVO]
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
regDAO.FeedDAO.insert(FeedDAO.java:18)
regController.FbackController.doPost(FbackController.java:53)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause

java.sql.SQLException: 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 'TO, From, Message) values (100170107051, 7541, '123')' at line 1
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1166)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1082)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1067)
org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
regDAO.FeedDAO.insert(FeedDAO.java:18)
regController.FbackController.doPost(FbackController.java:53)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)


My hbm file for feedback is:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="regVO.FeedbackVO" table="AP_feedback_mst">
<id name="id" column="Id">
<generator class="native"></generator>
</id>

<property name="to" column="TO"></property>
<property name="from" column="From"></property>
<property name="msg" column="Message"></property>

</class>

</hibernate-mapping>

And My configuration file is :

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost/alumni</property>
<property name="connection.username">root</property>
<property name="connection.password">root@123</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<mapping resource="feed.hbm.xml" ></mapping>
<mapping resource="user.hbm.xml"></mapping>
<mapping resource="department.hbm.xml" ></mapping>
<mapping resource="event.hbm.xml" ></mapping>
<mapping resource="category.hbm.xml" ></mapping>
<mapping resource="complain.hbm.xml" ></mapping>
<mapping resource="country.hbm.xml" ></mapping>
<mapping resource="state.hbm.xml" ></mapping>
<mapping resource="city.hbm.xml" ></mapping>
<mapping resource="subcategory.hbm.xml" ></mapping>
<mapping resource="securityquestion.hbm.xml" ></mapping>
<mapping resource="semester.hbm.xml" ></mapping>
<mapping resource="sendnotification.hbm.xml" ></mapping>
<mapping resource="job.hbm.xml" ></mapping>
<mapping resource="tutorial.hbm.xml" ></mapping>
<mapping resource="achieve.hbm.xml" ></mapping>
<mapping resource="attachmentVO.hbm.xml"/>
<mapping resource="attachmentMappingVO.hbm.xml"/>

</session-factory>

</hibernate-configuration>


I am just saving the FeedbackVO object by session1.save(fObj);

please help..........
Anil Sable
Greenhorn

Joined: Jan 08, 2012
Posts: 7
TRY TO AVOID COLUMN NAME LIKE TO, FROM THEY ARE MYSQL KEYWORD WHICH HIBERNATE CANNOT RECOGNIZE . . . . TRY ANOTHER NAME IN YOUR TABLE FOR THE COLUMN NAME TO AND FROM AND
CHANGE TO HIBERNATE MAPPING FILE ACCORDINGLY . . . . . MAKE YOUR PRIMARY KEY AUTO INCREMENT . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.hibernate.exception.SQLGrammarException: could not insert
 
Similar Threads
Cannot add or update a child row: a foreign key constraint fails
SQLGrammerException in Hibernate
Issue in inserting into DB using Hibernate, Spring
Problem in mapping
New to Hibernate.help with org.hibernate.HibernateException: Unable to instantiate default tuplizer