在hibernate异常中打开查询

时间:2011-09-13 13:05:30

标签: java hibernate hql openquery

我正在使用struts2hibernate进行开发。

我用来运行我的打开查询的Java代码如下

String hql ="insert into  "+"OPENQUERY(OracleLinkedServer, \'SELECT * 
FROM     report_access_log\') "+"(CALLINGHOST, ACCESSTIMESTAMP, 
HTTPREQUESTMETHOD, ACCESSURL,"+"HTTPRESPONSECODE, HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID)"+"  values "+          "(:CALLINGHOST,:ACCESSTIMESTAMP,:HTTPREQUESTMETHOD,:ACCESSURL,:HTTPRESPO
NSECODE," 
+          ":HTTPRESPONSETIMEMILLI,:USERNAME,:REPORTNAME,"+           "(select * from 
OPENQUERY(OracleLinkedServer,"+                   "\'select SQ_RPT_ACC_LOG_ID.nextval 
from dual\')))";         Query query=session.createQuery(hql);         query.setString
("CALLINGHOST", userLogReport.get(0).toString());         query.setDate
("ACCESSTIMESTAMP", (Date)userLogReport.get(1));         query.setString
("HTTPREQUESTMETHOD", userLogReport.get(2).toString());         query.setString
("ACCESSURL", userLogReport.get(3).toString());         query.setString
("HTTPRESPONSECODE", userLogReport.get(4).toString());         query.setInteger
("HTTPRESPONSETIMEMILLI", (Integer)userLogReport.get(5));         query.setString
("USERNAME", userLogReport.get(6).toString());         query.setString("REPORTNAME", 
userLogReport.get(7).toString()); 

以下是在控制台中打印的查询。当我在SQL编辑器中运行以下查询时,它已成功插入,但不是从Java。我收到以下错误消息。

SQL查询:

insert into  OPENQUERY(OracleLinkedServer, 'SELECT * FROM report_access_log') (CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,HTTPRESPONSECODE, HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID) values (?,?,?,?,?,?,?,?,(select * from OPENQUERY(OracleLinkedServer,'select SQ_RPT_ACC_LOG_ID.nextval from dual')))

以下是堆栈跟踪:

BLRSAL132772D是我的服务器

17:30:55,279 INFO  [STDOUT] Hibernate: insert into  OPENQUERY(OracleLinkedServer, 'SELECT * FROM report_access_log') (CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,HTTPRESPONSECODE, HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID) values (?,?,?,?,?,?,?,?,(select * from OPENQUERY(OracleLinkedServer,'select SQ_RPT_ACC_LOG_ID.nextval from dual')))
17:30:55,341 INFO  [STDOUT] 2011-09-13 17:30:55,341 [ERROR] org.hibernate.util.JDBCExceptionReporter - MSDTC on server 'BLRSAL132772D\INTAPP2_5' is unavailable.
17:30:55,341 ERROR [STDERR] org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query
17:30:55,341 ERROR [STDERR]     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
17:30:55,341 ERROR [STDERR]     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
17:30:55,341 ERROR [STDERR]     at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:198)
17:30:55,341 ERROR [STDERR]     at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1191)
17:30:55,341 ERROR [STDERR]     at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:357)
17:30:55,341 ERROR [STDERR]     at com.bby.ci.promoads.imageviewer.dataaccess.impl.UserLogReportsDAOImpl.insertUserLogReports(UserLogReportsDAOImpl.java:83)
17:30:55,341 ERROR [STDERR]     at com.bby.ci.promoads.imageviewer.struts.action.ViewImagesAction.execute(ViewImagesAction.java:270)
17:30:55,341 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:30:55,341 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
17:30:55,341 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
17:30:55,341 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Unknown Source)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
17:30:55,341 ERROR [STDERR]     at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,341 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
17:30:55,356 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,387 ERROR [STDERR]     at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
17:30:55,387 ERROR [STDERR]     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
17:30:55,387 ERROR [STDERR]     at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
17:30:55,387 ERROR [STDERR]     at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
17:30:55,387 ERROR [STDERR]     at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
17:30:55,387 ERROR [STDERR]     at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
17:30:55,387 ERROR [STDERR]     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
17:30:55,387 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
17:30:55,387 ERROR [STDERR]     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
17:30:55,387 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
17:30:55,387 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
17:30:55,387 ERROR [STDERR]     at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
17:30:55,387 ERROR [STDERR]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
17:30:55,403 ERROR [STDERR]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
17:30:55,403 ERROR [STDERR]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
17:30:55,403 ERROR [STDERR]     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
17:30:55,403 ERROR [STDERR]     at java.lang.Thread.run(Unknown Source)
17:30:55,403 ERROR [STDERR] Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: MSDTC on server 'BLRSAL132772D\INTAPP2_5' is unavailable.
17:30:55,403 ERROR [STDERR]     at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
17:30:55,403 ERROR [STDERR]     at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
17:30:55,403 ERROR [STDERR]     at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388)
17:30:55,434 ERROR [STDERR]     at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338)
17:30:55,434 ERROR [STDERR]     at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
17:30:55,434 ERROR [STDERR]     at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
17:30:55,434 ERROR [STDERR]     at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
17:30:55,434 ERROR [STDERR]     at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
17:30:55,434 ERROR [STDERR]     at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:306)
17:30:55,434 ERROR [STDERR]     at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:189)
17:30:55,434 ERROR [STDERR]     ... 77 more

1 个答案:

答案 0 :(得分:0)

检查线

org.hibernate.util.JDBCExceptionReporter - MSDTC on server 'BLRSAL132772D\INTAPP2_5' is unavailable. 17:30:55,341 ERROR [STDERR] org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query

SQL服务器抱怨MSDTC服务没有运行......

要解决此问题,只需使用Windows服务管理器启动服务“分布式事务处理协调器”。

以下是启动服务的详细步骤

  • 点击开始 - >控制面板 - >管理工具 - >服务(或只需在运行命令框中键入services.msc并按Enter键);
  • 显示“服务”管理员
  • 滚动列表并标识服务“Distributed Transaction Coordinator”
  • 在服务上,选择“开始”

在此之后问题必须消失。