Hibernate--关键字 'user' 附近有语法错误

刚刚学hibernate,总是出现问题。现在给大家一些建议,免得浪费时间,在那里不停的调啊,调啊。

关键字 'user' 附近有语法错误

GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: insert into user-addr.dbo.user (user_name, age) values (?, ?)
org.hibernate.exception.SQLGrammarException: could not insert: [com.h1.dao.User]
 at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
 at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
 at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
 at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
 at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
 at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
 at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
 at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
 at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
 at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
 at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
 at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
 at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
 at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
 at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
 at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
 at com.h1.dao.UserDAO.save(UserDAO.java:34)
 at com.h1.dao.UserDAO.main(UserDAO.java:165)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 关键字 'user' 附近有语法错误。
 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
 at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
 at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388)
 at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338)
 at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
 at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
 at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
 at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
 at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:306)
 at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
 at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)

注意你的数据库名字是不是与user有关,user貌似是数据库什么的关键字,不能用关键字。我的数据库名字用了user-addr,并且某个*.hbm.xml文件用了如下写法

<hibernate-mapping>
    <class name="com.h1.dao.Client" table="client" schema="dbo" catalog="user- addr">

...

是配置文件写错啦,用了关键字

注意user不能用(会报错,关键字 'user' 附近有语法错误), - 也不能用(会报错,'-' 附近有语法错误。)。

 


出处:http://blog.csdn.net/cocodehouse/archive/2010/06/26/5695306.aspx

阅读更多

没有更多推荐了,返回首页