potahai 2008-11-07 15:43
浏览 306
已采纳

HQL 问题 !!!

HQL支持 insert into 表名1 select * from 表名2 吗
[b]问题补充:[/b]
这个是继承了org.springframework.orm.hibernate3.support.HibernateDaoSupport类

——————————————————————————————————————
s = this.getSession();
String hql = "insert into Articles select a.artiId,a.artiName,a.artiSpec,a.artiModel,a.artiMarkPrice,a.artiAssociatorPrice,a.artiInfo,a.artiFlag," +
"ac.artiClassName,ab.artiBrandName,ap.artiPhotoPath " +
"from Article a,Articlass ac,Artibrand ab,Artiphoto ap" +
" where a.artiClassId = ac.artiClassId and a.artiBrandId = ab.artiBrandId and a.artiPhotoId = ap.artiPhotoId";
t = s.beginTransaction();
s.createQuery(hql).executeUpdate();
t.commit();

出现问题
——————————————————————————————————
org.hibernate.hql.ast.QuerySyntaxException: expecting OPEN, found 'select' near line 1, column 22 [insert into Articles select a.artiId,a.artiName,a.artiSpec,a.artiModel,a.artiMarkPrice,a.artiAssociatorPrice,a.artiInfo,a.artiFlag,ac.artiClassName,ab.artiBrandName,ap.artiPhotoPath from com.articleweb.model.Article a,com.articleweb.model.Articlass ac,com.articleweb.model.Artibrand ab,com.articleweb.model.Artiphoto ap where a.artiClassId = ac.artiClassId and a.artiBrandId = ab.artiBrandId and a.artiPhotoId = ap.artiPhotoId]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:244)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
at com.articleweb.model.control.ArticleControl.insertArticles(ArticleControl.java:27)
at com.articleweb.struts.action.ArticlesAction.showarti(ArticlesAction.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)

[b]问题补充:[/b]
我是在MYSQL数据上 用SQL 试过之后才到HQL用的。
既然HQL支持的就不应该有这样的问题吧。查出来的结果结构和要导入的表结果是相同的。

[b]问题补充:[/b]
Hibernate 3.1

数据库绝对支持这个方法 我试用过后才到HQL里运用的。

[b]问题补充:[/b]
要是可以用SQL的问题就不存在了。郁闷中。
[b]问题补充:[/b]
楼上的高手不是说HQL支持这个语法的吗
[b]问题补充:[/b]
这个跟关联查询有关系吗?字段和表名我都是按类对象来写的。
就是不行。 无奈了。

快背熟了 没错别字 还是不行
[b]问题补充:[/b]
insert into Articles select a.artiId,a.artiName,a.artiSpec,a.artiModel,a.artiMarkPrice,a.artiAssociatorPrice,a.artiInfo,a.artiFlag," +
"ac.artiClassName,ab.artiBrandName,ap.artiPhotoPath " +
"from Article a,Articlass ac,Artibrand ab,Artiphoto ap" +
" where a.artiClassId = ac.artiClassId and a.artiBrandId = ab.artiBrandId and a.artiPhotoId = ap.artiPhotoId
[b]问题补充:[/b]
String hql = "insert into Articles(artiId,artiName,artiSpec,artiModel,artiMarkPrice,artiAssociatorPrice,artiInfo,artiFlag,artiClassName,artiBrandName,artiPhotoPath)" +
" select a.artiId,a.artiName,a.artiSpec,a.artiModel,a.artiMarkPrice,a.artiAssociatorPrice,a.artiInfo,a.artiFlag," +
"ac.artiClassName,ab.artiBrandName,ap.artiPhotoPath " +
"from Article a,Articlass ac,Artibrand ab,Artiphoto ap" +
" where a.artiClassId = ac.artiClassId and a.artiBrandId = ab.artiBrandId and a.artiPhotoId = ap.artiPhotoId";
[b]问题补充:[/b]
异常变了
——————————————————————————————————————
org.hibernate.exception.ConstraintViolationException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:334)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:209)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1126)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at com.articleweb.model.control.ArticleControl.insertArticles(ArticleControl.java:28)
at com.articleweb.struts.action.ArticlesAction.showarti(ArticlesAction.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: Duplicate entry '1' for key 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1085)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:670)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1159)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1076)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1061)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 33 more
16:58:21,437 DEBUG JDBCTransaction:152 - rollback
16:58:21,437 DEBUG JDBCTransaction:193 - re-enabling autocommit
16:58:21,437 DEBUG JDBCTransaction:163 - rolled back JDBC Connection
16:58:21,437 DEBUG QueryTranslatorImpl:236 - parse() - HQL: from com.articleweb.model.Articles
16:58:21,437 DEBUG ErrorCounter:68 - throwQueryException() : no errors
16:58:21,437 DEBUG HqlSqlBaseWalker:111 - select << begin [level=1, statement=select]
16:58:21,437 DEBUG FromElement:104 - FromClause{level=1} : com.articleweb.model.Articles (no alias) -> articles0_
16:58:21,437 DEBUG HqlSqlBaseWalker:117 - select : finishing up [level=1, statement=select]
16:58:21,437 DEBUG HqlSqlWalker:511 - processQuery() : ( SELECT ( FromClause{level=1} myweb.articles articles0_ ) )
16:58:21,453 DEBUG HqlSqlWalker:713 - Derived SELECT clause created.
16:58:21,453 DEBUG JoinProcessor:128 - Using FROM fragment [myweb.articles articles0_]
16:58:21,453 DEBUG HqlSqlBaseWalker:123 - select >> end [level=1, statement=select]
16:58:21,453 DEBUG ErrorCounter:68 - throwQueryException() : no errors
16:58:21,453 DEBUG QueryTranslatorImpl:206 - HQL: from com.articleweb.model.Articles
16:58:21,453 DEBUG QueryTranslatorImpl:207 - SQL: select articles0_.ArtiID as ArtiID11_, articles0_.ArtiName as ArtiName11_, articles0_.ArtiSpec as ArtiSpec11_, articles0_.ArtiModel as ArtiModel11_, articles0_.ArtiMarkPrice as ArtiMark5_11_, articles0_.ArtiAssociatorPrice as ArtiAsso6_11_, articles0_.ArtiInfo as ArtiInfo11_, articles0_.ArtiFlag as ArtiFlag11_, articles0_.ArtiClassName as ArtiClas9_11_, articles0_.ArtiBrandName as ArtiBra10_11_, articles0_.ArtiPhotoPath as ArtiPho11_11_ from myweb.articles articles0_
16:58:21,453 DEBUG ErrorCounter:68 - throwQueryException() : no errors
[b]问题补充:[/b]
详细异常
————————————————————————————————————————16:58:20,703 DEBUG JDBCTransaction:54 - begin
16:58:20,718 DEBUG JDBCTransaction:59 - current autocommit status: true
16:58:20,718 DEBUG JDBCTransaction:62 - disabling autocommit
16:58:20,890 DEBUG QueryTranslatorImpl:236 - parse() - HQL: insert into Articles(artiId,artiName,artiSpec,artiModel,artiMarkPrice,artiAssociatorPrice,artiInfo,artiFlag,artiClassName,artiBrandName,artiPhotoPath) select a.artiId,a.artiName,a.artiSpec,a.artiModel,a.artiMarkPrice,a.artiAssociatorPrice,a.artiInfo,a.artiFlag,ac.artiClassName,ab.artiBrandName,ap.artiPhotoPath from com.articleweb.model.Article a,com.articleweb.model.Articlass ac,com.articleweb.model.Artibrand ab,com.articleweb.model.Artiphoto ap where a.artiClassId = ac.artiClassId and a.artiBrandId = ab.artiBrandId and a.artiPhotoId = ap.artiPhotoId
16:58:20,906 DEBUG ErrorCounter:68 - throwQueryException() : no errors
16:58:21,015 DEBUG HqlSqlBaseWalker:111 - insert << begin [level=1, statement=insert]
16:58:21,062 DEBUG HqlSqlBaseWalker:111 - select << begin [level=2, statement=insert]
16:58:21,109 DEBUG FromElement:104 - FromClause{level=1} : com.articleweb.model.Article (a) -> article0_
16:58:21,109 DEBUG FromElement:104 - FromClause{level=1} : com.articleweb.model.Articlass (ac) -> articlass1_
16:58:21,109 DEBUG FromElement:104 - FromClause{level=1} : com.articleweb.model.Artibrand (ab) -> artibrand2_
16:58:21,125 DEBUG FromElement:104 - FromClause{level=1} : com.articleweb.model.Artiphoto (ap) -> artiphoto3_
16:58:21,125 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,125 DEBUG DotNode:541 - getDataType() : artiId -> org.hibernate.type.IntegerType@e1cfa7
16:58:21,125 DEBUG FromReferenceNode:51 - Resolved : a.artiId -> article0_.ArtiId
16:58:21,125 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,125 DEBUG DotNode:541 - getDataType() : artiName -> org.hibernate.type.StringType@10811b5
16:58:21,125 DEBUG FromReferenceNode:51 - Resolved : a.artiName -> article0_.ArtiName
16:58:21,125 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,125 DEBUG DotNode:541 - getDataType() : artiSpec -> org.hibernate.type.StringType@10811b5
16:58:21,125 DEBUG FromReferenceNode:51 - Resolved : a.artiSpec -> article0_.ArtiSpec
16:58:21,156 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,156 DEBUG DotNode:541 - getDataType() : artiModel -> org.hibernate.type.StringType@10811b5
16:58:21,156 DEBUG FromReferenceNode:51 - Resolved : a.artiModel -> article0_.ArtiModel
16:58:21,156 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,156 DEBUG DotNode:541 - getDataType() : artiMarkPrice -> org.hibernate.type.FloatType@1af5853
16:58:21,156 DEBUG FromReferenceNode:51 - Resolved : a.artiMarkPrice -> article0_.ArtiMarkPrice
16:58:21,156 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,156 DEBUG DotNode:541 - getDataType() : artiAssociatorPrice -> org.hibernate.type.FloatType@1af5853
16:58:21,156 DEBUG FromReferenceNode:51 - Resolved : a.artiAssociatorPrice -> article0_.ArtiAssociatorPrice
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,171 DEBUG DotNode:541 - getDataType() : artiInfo -> org.hibernate.type.StringType@10811b5
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : a.artiInfo -> article0_.ArtiInfo
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,171 DEBUG DotNode:541 - getDataType() : artiFlag -> org.hibernate.type.IntegerType@e1cfa7
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : a.artiFlag -> article0_.ArtiFlag
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : ac -> ArtiClassId
16:58:21,171 DEBUG DotNode:541 - getDataType() : artiClassName -> org.hibernate.type.StringType@10811b5
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : ac.artiClassName -> articlass1_.ArtiClassName
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : ab -> ArtiBrandId
16:58:21,171 DEBUG DotNode:541 - getDataType() : artiBrandName -> org.hibernate.type.StringType@10811b5
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : ab.artiBrandName -> artibrand2_.ArtiBrandName
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : ap -> ArtiPhotoId
16:58:21,171 DEBUG DotNode:541 - getDataType() : artiPhotoPath -> org.hibernate.type.StringType@10811b5
16:58:21,171 DEBUG FromReferenceNode:51 - Resolved : ap.artiPhotoPath -> artiphoto3_.ArtiPhotoPath
16:58:21,218 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,218 DEBUG DotNode:541 - getDataType() : artiClassId -> org.hibernate.type.IntegerType@e1cfa7
16:58:21,218 DEBUG FromReferenceNode:51 - Resolved : a.artiClassId -> article0_.ArtiClassId
16:58:21,218 DEBUG FromReferenceNode:51 - Resolved : ac -> ArtiClassId
16:58:21,218 DEBUG DotNode:541 - getDataType() : artiClassId -> org.hibernate.type.IntegerType@e1cfa7
16:58:21,218 DEBUG FromReferenceNode:51 - Resolved : ac.artiClassId -> articlass1_.ArtiClassId
16:58:21,218 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,218 DEBUG DotNode:541 - getDataType() : artiBrandId -> org.hibernate.type.IntegerType@e1cfa7
16:58:21,218 DEBUG FromReferenceNode:51 - Resolved : a.artiBrandId -> article0_.ArtiBrandId
16:58:21,218 DEBUG FromReferenceNode:51 - Resolved : ab -> ArtiBrandId
16:58:21,218 DEBUG DotNode:541 - getDataType() : artiBrandId -> org.hibernate.type.IntegerType@e1cfa7
16:58:21,218 DEBUG FromReferenceNode:51 - Resolved : ab.artiBrandId -> artibrand2_.ArtiBrandId
16:58:21,218 DEBUG FromReferenceNode:51 - Resolved : a -> ArtiId
16:58:21,218 DEBUG DotNode:541 - getDataType() : artiPhotoId -> org.hibernate.type.IntegerType@e1cfa7
16:58:21,234 DEBUG FromReferenceNode:51 - Resolved : a.artiPhotoId -> article0_.ArtiPhotoId
16:58:21,234 DEBUG FromReferenceNode:51 - Resolved : ap -> ArtiPhotoId
16:58:21,234 DEBUG DotNode:541 - getDataType() : artiPhotoId -> org.hibernate.type.IntegerType@e1cfa7
16:58:21,234 DEBUG FromReferenceNode:51 - Resolved : ap.artiPhotoId -> artiphoto3_.ArtiPhotoId
16:58:21,234 DEBUG HqlSqlBaseWalker:117 - select : finishing up [level=2, statement=insert]
16:58:21,234 DEBUG HqlSqlWalker:511 - processQuery() : ( SELECT ( {select clause} ( article0_.ArtiId ArtiId artiId ) ( article0_.ArtiName ArtiId artiName ) ( article0_.ArtiSpec ArtiId artiSpec ) ( article0_.ArtiModel ArtiId artiModel ) ( article0_.ArtiMarkPrice ArtiId artiMarkPrice ) ( article0_.ArtiAssociatorPrice ArtiId artiAssociatorPrice ) ( article0_.ArtiInfo ArtiId artiInfo ) ( article0_.ArtiFlag ArtiId artiFlag ) ( articlass1_.ArtiClassName ArtiClassId artiClassName ) ( artibrand2_.ArtiBrandName ArtiBrandId artiBrandName ) ( artiphoto3_.ArtiPhotoPath ArtiPhotoId artiPhotoPath ) ) ( FromClause{level=1} myweb.article article0_ myweb.articlass articlass1_ myweb.artibrand artibrand2_ myweb.artiphoto artiphoto3_ ) ( where ( and ( and ( = ( article0_.ArtiClassId ArtiId artiClassId ) ( articlass1_.ArtiClassId ArtiClassId artiClassId ) ) ( = ( article0_.ArtiBrandId ArtiId artiBrandId ) ( artibrand2_.ArtiBrandId ArtiBrandId artiBrandId ) ) ) ( = ( article0_.ArtiPhotoId ArtiId artiPhotoId ) ( artiphoto3_.ArtiPhotoId ArtiPhotoId artiPhotoId ) ) ) ) )
16:58:21,281 DEBUG JoinProcessor:128 - Using FROM fragment [myweb.artiphoto artiphoto3_]
16:58:21,281 DEBUG JoinProcessor:128 - Using FROM fragment [myweb.artibrand artibrand2_]
16:58:21,281 DEBUG JoinProcessor:128 - Using FROM fragment [myweb.articlass articlass1_]
16:58:21,281 DEBUG JoinProcessor:128 - Using FROM fragment [myweb.article article0_]
16:58:21,281 DEBUG HqlSqlBaseWalker:123 - select >> end [level=2, statement=insert]
16:58:21,281 DEBUG HqlSqlBaseWalker:117 - insert : finishing up [level=1, statement=insert]
16:58:21,281 DEBUG HqlSqlBaseWalker:123 - insert >> end [level=1, statement=insert]
16:58:21,281 DEBUG ErrorCounter:68 - throwQueryException() : no errors
16:58:21,328 DEBUG ErrorCounter:68 - throwQueryException() : no errors
16:58:21,437 WARN JDBCExceptionReporter:71 - SQL Error: 1062, SQLState: 23000
16:58:21,437 ERROR JDBCExceptionReporter:72 - Duplicate entry '1' for key 1
org.hibernate.exception.ConstraintViolationException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:334)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:209)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1126)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at com.articleweb.model.control.ArticleControl.insertArticles(ArticleControl.java:28)
at com.articleweb.struts.action.ArticlesAction.showarti(ArticlesAction.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: Duplicate entry '1' for key 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1085)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:670)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1159)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1076)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1061)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 33 more
16:58:21,437 DEBUG JDBCTransaction:152 - rollback
16:58:21,437 DEBUG JDBCTransaction:193 - re-enabling autocommit
16:58:21,437 DEBUG JDBCTransaction:163 - rolled back JDBC Connection
16:58:21,437 DEBUG QueryTranslatorImpl:236 - parse() - HQL: from com.articleweb.model.Articles
16:58:21,437 DEBUG ErrorCounter:68 - throwQueryException() : no errors
16:58:21,437 DEBUG HqlSqlBaseWalker:111 - select << begin [level=1, statement=select]
16:58:21,437 DEBUG FromElement:104 - FromClause{level=1} : com.articleweb.model.Articles (no alias) -> articles0_
16:58:21,437 DEBUG HqlSqlBaseWalker:117 - select : finishing up [level=1, statement=select]
16:58:21,437 DEBUG HqlSqlWalker:511 - processQuery() : ( SELECT ( FromClause{level=1} myweb.articles articles0_ ) )
16:58:21,453 DEBUG HqlSqlWalker:713 - Derived SELECT clause created.
16:58:21,453 DEBUG JoinProcessor:128 - Using FROM fragment [myweb.articles articles0_]
16:58:21,453 DEBUG HqlSqlBaseWalker:123 - select >> end [level=1, statement=select]
16:58:21,453 DEBUG ErrorCounter:68 - throwQueryException() : no errors
16:58:21,453 DEBUG QueryTranslatorImpl:206 - HQL: from com.articleweb.model.Articles
16:58:21,453 DEBUG QueryTranslatorImpl:207 - SQL: select articles0_.ArtiID as ArtiID11_, articles0_.ArtiName as ArtiName11_, articles0_.ArtiSpec as ArtiSpec11_, articles0_.ArtiModel as ArtiModel11_, articles0_.ArtiMarkPrice as ArtiMark5_11_, articles0_.ArtiAssociatorPrice as ArtiAsso6_11_, articles0_.ArtiInfo as ArtiInfo11_, articles0_.ArtiFlag as ArtiFlag11_, articles0_.ArtiClassName as ArtiClas9_11_, articles0_.ArtiBrandName as ArtiBra10_11_, articles0_.ArtiPhotoPath as ArtiPho11_11_ from myweb.articles articles0_
16:58:21,453 DEBUG ErrorCounter:68 - throwQueryException() : no errors

  • 写回答

15条回答 默认 最新

  • iteye_521 2008-11-07 17:04
    关注

    主键冲突了,嘿嘿

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(14条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划