Just learning hibernate, there are always problems. Now give everyone some advice, so as not to waste time, where the constant tune Ah, tune AH.
There is a syntax error near the keyword ' user '
Getgeneratedkeysdelegate.executeandextract (identitygenerator.java:73)
Log4j:warn No Appenders could is found for logger (org.hibernate.cfg.Environment).
Log4j:warn Initialize the log4j system properly.
Hibernate:insert to 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: There is a syntax error near the keyword ' 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)
Note that your database name is not related to user, user seems to be the database of what keyword, can not use keywords. My database name is USER-ADDR, and a *.hbm.xml file uses the following notation
<class name= "com.h1.dao.Client" table= "Client" schema= "dbo" catalog= "USER-ADDR" >
...
Is the configuration file is wrong, using the keyword
Note that user can not use (will error, the keyword ' user ' near the syntax error),-also can not use (will error, '-' There is a syntax error nearby. )。
Source: http://blog.csdn.net/cocodehouse/archive/2010/06/26/5695306.aspx