GenericADOException: could not insert
nhibernate, nhibernate-mapping
Solution
Order is a reserved word. just add some back ticks to your class definition and NHibernate will escape the table name for you automatically.
<class name="order" table="`order`" lazy="true" >
Problem
I'm trying to save my order object in the database that has a relationship many-to-one with the table pastaIndividual. But, I'm getting this exception: Error: NHibernate.Exceptions.GenericADOException: could not insert: [FrancosPoS.DBMapping.order][SQL: INSERT INTO order (price, cash, credit, obs) VALUES (?, ?, ?, ?);SELECT LAST_INSERT_ID()] ---> MySql.Data.MySqlClient.MySqlException: 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 'order (price, cash, credit, obs) VALUES ('123', 1, 0, 'Nhibernate');SELECT LAST_' at line 1 Here is my order mapping table: ``` <?xml version="1.0" encoding="utf-8"?> <hibernate-mapping assembly="FrancosPoS" namespace="FrancosPoS.DBMapping" xmlns="urn:nhibernate-mapping-2.2"> <class name="order" table="order" lazy="true" > <id name="idOrder"> <generator class="identity" /> </id> <set name="pastaIndividual" table="pasta_individual" cascade="save-update"> <key column="idPastaI"/> <one-to-many class="pastaIndividual"/> </set> <!--<many-to-one insert="false" update="false" lazy="false" name="pastaIndividual" class="FrancosPoS.DBMapping.pastaIndividual"> <column name="idPastaI" sql-type="int(11)" not-null="false" /> </many-to-one>--> <many-to-one insert="false" update="false" lazy="false" name="pastaCombo" class="FrancosPoS.DBMapping.pastaCombo"> <column name="idPastaC" sql-type="int(11)" not-null="false" /> </many-to-one> <many-to-one insert="false" update="false" lazy="false" name="pastaFeast" class="FrancosPoS.DBMapping.pastaFeast"> <column name="idPastaF" sql-type="int(11)" not-null="false" /> </many-to-one> <many-to-one insert="false" update="false" lazy="false" name="salad" class="FrancosPoS.DBMapping.salad"> <column name="idSalad" sql-type="int(11)" not-null="false" /> </many-to-one> <many-to-one insert="false" update="false" lazy="false" name="drink" class="FrancosPoS.DBMapping.drink"> <column name="idDrink" sql-type="int(11)" not-null="false" /> </many-to-one> <property name="price"> <column name="price" sql-type="decimal(8,4)" not-null="true" /> </property> <property name="cash"> <column name="cash" sql-type="tinyint(1)" not-null="false" /> </property> <property name="credit"> <column name="credit" sql-type="tinyint(1)" not-null="false" /> </property> <property name="obs"> <column name="obs" sql-type="varchar(150)" not-null="false" /> </property> </class> </hibernate-mapping> ``` Here is my pastaIndividual mapping: ``` <?xml version="1.0" encoding="utf-8"?> <hibernate-mapping assembly="FrancosPoS" namespace="FrancosPoS.DBMapping" xmlns="urn:nhibernate-mapping-2.2"> <class name="pastaIndividual" table="pasta_individual" lazy="true" > <id name="idPastaI"> <generator class="identity" /> </id> <property name="type"> <column name="type" sql-type="varchar(25)" not-null="true" /> </property> <property name="price"> <column name="price" sql-type="decimal(8,4)" not-null="true" /> </property> </class> </hibernate-mapping> ``` I've tried on order mapping to use the `<set>` or just `<many-to-one>`, but the same error happen. Maybe am I missing some inverse property? Thanks.