I am using struts2
and hibernate
for development.
The Java Code i used to run my open query is as follows
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());
The following is the query printed in the console. When i run the following query in SQL editor it is successfully inserted but not from Java. I get the following error message.
SQL Query:
insert into OPENQUERY(OracleLinkedServer, 'SELECT * FROM report_access_log') (CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,HTTPRESPONSECODE, HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID) value开发者_JAVA百科s (?,?,?,?,?,?,?,?,(select * from OPENQUERY(OracleLinkedServer,'select SQ_RPT_ACC_LOG_ID.nextval from dual')))
The following is the stack trace:
BLRSAL132772D is my server.
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
check the line
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 server is complaining that MSDTC service is not running...
To fix the problem just start the service “Distributed Transaction Coordinator” using Windows Service manager.
Here are the detailed steps for starting the service
- Click on Start–>Control Panel->Administrative Tools->Services (or simply type services.msc in the run command box and hit enter);
- display "Services" manager
- Scroll through the list and identify the service "Distributed Transaction Coordinator"
- Right on the service and choose "Start"
after this the problem must be gone.
精彩评论