postgresql org.hibernate.exception.SQLGrammarException: 无法插入:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3758105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.hibernate.exception.SQLGrammarException: could not insert:
提问by lakshmi
Hi Im running example using hibernate with postgresql 8.4, when i try to add it will dispay following error
嗨,我在 postgresql 8.4 中使用 hibernate 运行示例,当我尝试添加它时,将显示以下错误
org.hibernate.exception.SQLGrammarException: could not insert: [com.claystone.db.OrWorkgroup]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.claystone.server.setup.VehicleManager.AddWorkGroup(VehicleManager.java:700)
at com.claystone.server.setup.SetupServiceImpl.AddWorkGroup(SetupServiceImpl.java:1077)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:527)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:166)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: org.postgresql.util.PSQLException: ERROR: column "last_modified_time" is of type last_modified_time but expression is of type bytea
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:305)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)
... 38 more
How to solve this error.
如何解决这个错误。
回答by Maurice Perry
The type of the property (field) that you have mapped to the column 'last_modified_time' is not allowed for the type of the column. Either change the type of the column or the type of the property (field).
列的类型不允许您映射到列“last_modified_time”的属性(字段)的类型。更改列的类型或属性(字段)的类型。
回答by Pascal Ramboz
Check the context.xml file within $TOMCAT_HOME/conf/
, you might have a datasources conflict if one is declared several times.
检查 中的 context.xml 文件$TOMCAT_HOME/conf/
,如果多次声明,您可能会遇到数据源冲突。
You can display the list of resource names by typing:
您可以通过键入以下内容来显示资源名称列表:
$ egrep -i 'Resource[[:space:]]+name' /var/lib/tomcat6/conf/context.xml | awk '{print }' | sed 's/name=//g' | sed 's/"//g'
Indeed it can happen you've been working a few weeks or months ago on an old project for which you gave the same datasource name.
事实上,您几周或几个月前一直在一个旧项目上工作,您为其提供了相同的数据源名称,这可能会发生。
Other possible explanation: you might have a jar library conflict (upon mysql-connector-java for instance ), so check $TOMCAT_HOME/lib/ and deployed applications lib/ subfolders like $TOMCAT_HOME/webapps/YOUR_APPLICATION/WEB-INF/lib/.
其他可能的解释:您可能有 jar 库冲突(例如在 mysql-connector-java 上),因此请检查 $TOMCAT_HOME/lib/ 和已部署的应用程序 lib/ 子文件夹,如 $TOMCAT_HOME/webapps/YOUR_APPLICATION/WEB-INF/lib/。
Hope it helps !
希望能帮助到你 !
Pascal Ramboz (PERF IT company).
Pascal Ramboz(PERF IT 公司)。
回答by Shiva
Hi please check you cfg file, if you have 'create' in 'hbm2ddl.auto' change it to 'update'; it might be a problem
嗨,请检查您的 cfg 文件,如果您在“hbm2ddl.auto”中有“create”,请将其更改为“update”;这可能是个问题
<property name="hbm2ddl.auto">update</property>
回答by vaib
check the annotation on class @table(name=""),change the table name from existing one
检查类@table(name="") 上的注释,将表名从现有的更改为