-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: DB2 users...
PostPosted: Sat Sep 27, 2003 6:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I've just implemented query paging using rownumber() over() in DB2. I've tested this in DB2 8.1. Would someone please test this feature on DB2 6/7 for me? You need to call both setMaxResults()/setFirstResult() to make use of it.


Top
 Profile  
 
 Post subject: It doesn't work with distinct.
PostPosted: Tue Nov 11, 2003 4:37 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
If you use use distinct in the query that has maxResult set, it blows up, it puts the code as:

Code:
select * from ( select rownumber() over() as row_, distinct ... ) as temp_ where row_ <= ?


I think distinct should come *before* the rownumber() over() as row_.[/code]

_________________
- Brian


Top
 Profile  
 
 Post subject: Yikes - after more thought, can't use it with distinct.
PostPosted: Tue Nov 11, 2003 5:04 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
rownumber() over() as row_ makes every row distinct. That being said, I don't think I can use FirstResults for queries with distinct. Since I need only the first x rows of the report, which doesn't translate into x rows of the result set. Dammit.

Anyway, I'd just put a bugaboo in the docs to let people know that this may not be the solution they need for paging.

Thanks,

_________________
- Brian


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 10:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Thanks. This will be fixed:


http://opensource.atlassian.com/project ... key=HB-464


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 6:13 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 4:54 pm
Posts: 26
Location: Chicago, IL
This functionality is not working with the mainframe version of DB2 that we are using on my project (allegedly DB2 V7, but I'll try to dig up the exact version info). I am using the 2.1final release.

In the mean time, I just created a custom copy of DB2Dialect that returns false for "supportsLimit".


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 7:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
OK, we should at least mention that in the docs, if true.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 9:46 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 4:54 pm
Posts: 26
Location: Chicago, IL
This is the information I can glean so far. Still trying to get the exact version on the mainframe. (The select statement was improvised based on what Hibernate was generating, so please correct it if it was wrong.)

Here is the test code:
Code:
   public void testSelectRowNumberOver() throws Exception {
      DataSource ds = (DataSource) _lookup("jdbc/FssMidDataSource");
      assertNotNull("DataSource can't be null", ds);

      Connection conn = ds.getConnection();
      Statement stmt = conn.createStatement();

      DatabaseMetaData metadata = conn.getMetaData();
      _LOGGER.info(
         "databaseProductName: " + metadata.getDatabaseProductName());
      _LOGGER.info(
         "databaseProductVersion: " + metadata.getDatabaseProductVersion());
      _LOGGER.info("driverName: " + metadata.getDriverName());
      _LOGGER.info("driverVersion: " + metadata.getDriverVersion());
      _LOGGER.info("driverMajorVersion: " + metadata.getDriverMajorVersion());
      _LOGGER.info("driverMinorVersion: " + metadata.getDriverMinorVersion());

      String q1 = "select * from TFSDB01.SESN_STA_REF";
      String q2 =
         "select * from"
            + " ( select rownumber() over() as row_, this.*"
            + "   from TFSDB01.SESN_STA_REF this )"
            + " as temp_ where row_ <= 20";

      _LOGGER.info("executing first query [" + q1 + "]...");
      ResultSet rs1 = stmt.executeQuery(q1);
      rs1.close();

      _LOGGER.info("executing second query [" + q2 + "]...");
      ResultSet rs2 = stmt.executeQuery(q2);

      _LOGGER.info("closing resources...");
      rs2.close();
      stmt.close();
      conn.close();
   }




And the result:


Code:
INFO  common.DatabaseConnectivityTest - databaseProductName: DB2
INFO  common.DatabaseConnectivityTest - databaseProductVersion: 07.01.0001
INFO  common.DatabaseConnectivityTest - driverName: IBM DB2 JDBC 2.0 Type 2
INFO  common.DatabaseConnectivityTest - driverVersion: 07.02.0000
INFO  common.DatabaseConnectivityTest - driverMajorVersion: 7
INFO  common.DatabaseConnectivityTest - driverMinorVersion: 1
INFO  common.DatabaseConnectivityTest - executing first query [select * from TFSDB01.SESN_STA_REF]...
INFO  common.DatabaseConnectivityTest - executing second query [select * from ( select rownumber() over() as row_, this.*   from TFSDB01.SESN_STA_REF this ) as temp_ where row_ <= 20]...
DEBUG util.StringUtil - >exceptionToString = [COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2] SQL0104N  An unexpected token "(" was found following "".  Expected tokens may include:  ", FROM INTO ".  SQLSTATE=42601

   at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:260)
   at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:197)
   at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(SQLExceptionGenerator.java:448)
   at COM.ibm.db2.jdbc.app.DB2Statement.execute2(DB2Statement.java:449)
   at COM.ibm.db2.jdbc.app.DB2Statement.executeQuery(DB2Statement.java:369)
   at com.ibm.ejs.cm.proxy.StatementProxy.executeQueryCommon(StatementProxy.java:368)
   at com.ibm.ejs.cm.proxy.StatementProxy.executeQuery(StatementProxy.java:331)
   at ....
[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.