在休眠中打开查询

发布于 2024-12-04 10:36:35 字数 2311 浏览 2 评论 0原文

我在我的问题中使用了 struts 和 hibernate。我尝试了以下查询

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,:HTTPRESPONSECODE," +
         ":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());

控制台上打印的查询如下

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

我在第 79 列处收到查询语法异常,即 (CALINGHOST,...

但是当我在 SQL 中运行查询时,它正在执行。查询如下

insert into  OPENQUERY(OracleLinkedServer, 'SELECT * FROM report_access_log') 
(CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,HTTPRESPONSECODE, 
HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID) values 
('10.87.192.246','GET','/cci/bby/ImageViewer/viewImages.action','200',6,'su','Insert 
Review',(select * from OPENQUERY(OracleLinkedServer,'select SQ_RPT_ACC_LOG_ID.nextval 
from dual')))

请解释一下问题并为我提供一个从 Java 执行它的解决方案。 提前致谢。

I am using struts and hibernate in my problem. I tried the following query

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,:HTTPRESPONSECODE," +
         ":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 query printed on the console is as follows

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

i get a query syntax exception at column no 79 which is (CALLINGHOST,...

But when i ran the query in SQL it is getting executed. The query is as follows

insert into  OPENQUERY(OracleLinkedServer, 'SELECT * FROM report_access_log') 
(CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,HTTPRESPONSECODE, 
HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID) values 
('10.87.192.246','GET','/cci/bby/ImageViewer/viewImages.action','200',6,'su','Insert 
Review',(select * from OPENQUERY(OracleLinkedServer,'select SQ_RPT_ACC_LOG_ID.nextval 
from dual')))

Please explain the problem and provide me a solution for executing it from Java.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾性傲以野 2024-12-11 10:36:35

HQL 和 SQL 是两种不同的语言。 HQL 适用于 Hibernate 实体、它们的属性以及它们之间的关联。 SQL 适用于数据库表和列。

使用

Query query = session.createSQLQuery(sql); 

而不是

Query query = session.createQuery(hql);

HQL and SQL are two different languqges. HQL works on Hibernate entities, their properties, and associations between them. SQL works on database tables and columns.

Use

Query query = session.createSQLQuery(sql); 

rather than

Query query = session.createQuery(hql);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文