2011-04-22 76 views
1

为什么以下查询在MySql上失败?MySql INSERT失败

NHibernate: INSERT INTO UserSetting (userId, key, value) VALUES (?p0, ?p1, ?p2); ?p0 = ccda78da-689d-4d86-ba72-d65eaf281edf [Type: Guid (0)], ?p1 = 'Hello' [Type: String (5)], ?p2 = 'World' [Type: String (5)]

有了这个错误:

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 'key, value) VALUES ('ccda78da-689d-4d86-ba72-d65eaf281edf', 'Hello', 'World')' at line 1"}

回答

4

key是一个保留字。

试试这个:

INSERT INTO UserSetting (userId, `key`, value) VALUES (?p0, ?p1, ?p2) 
+0

@webwise例如:不幸的是,我不熟悉'NHibernate'。最好避免对象名称中的保留关键字。 – Quassnoi 2011-04-22 13:31:26