sqlserver中用了user关键子出现的问题

来源:互联网 发布:我国进口商品市场数据 编辑:程序博客网 时间:2024/04/29 10:04

sqlserver中用了user关键子出现的问题

将tomcat+struts+hibernate+mysql的一个小项目移植到sqlserver2000中,发现出现错误.

[DEBUG] SessionImpl - opened session

[DEBUG] SessionImpl - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects

[DEBUG] SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections

[DEBUG] QueryTranslator - HQL: select user from com.shjinbang.hibernate.User user

[DEBUG] QueryTranslator - SQL: select user0_.userid as x0_0_ from user user0_

[DEBUG] SessionFactoryImpl - prepared statement get: select user0_.userid as x0_0_ from user user0_

Hibernate: select user0_.userid as x0_0_ from user user0_

[DEBUG] JDBCExceptionReporter - SQL Exception <com.jnetdirect.jsql.JSQLException: 在关键字 'user' 附近有语法错误。>com.jnetdirect.jsql.JSQLException: 在关键字 'user' 附近有语法错误。

査google发现sqlserver竟然将user作为关键字,不让用户建立以user命名的表或字段,除非写成[user],而mysql没有这个情况.
将user改成employees后运行成功.当然,HQL语句中的相关user的名称也要同时修改.

总结经验,以后数据库命名要适当的复杂点,不要和关键子撞车.这个问题査了我半天时间.

原创粉丝点击