Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6743869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:00:51+00:00 2026-05-26T12:00:51+00:00

I have below SQL query: SELECT * FROM ( SELECT S.aCol, S.bCol, S.cCol, ROW_NUMBER()

  • 0

I have below SQL query:

SELECT * FROM (
  SELECT S.aCol, S.bCol, S.cCol, ROW_NUMBER() OVER (ORDER BY S.cCol ASC) AS R 
  FROM myTable S WHERE S.cCol LIKE 'abc%') AS TEMP 
WHERE R BETWEEN 0 AND 10 FOR FETCH ONLY

Basically this query serves pagination. The between clause will have different values for every fetch.

Now I want to implement the same query using JPA.

I found the below reference article from one SO question:

http://weblogs.java.net/blog/2007/05/31/pagination-data-sets-sample-application-using-jsf-catalog-facade-stateless-session-a

But in this article the resultant list is directly passed over to view. However, in my case I want to set the result columns in a transfer object (mySearchTO) as attributes.

Something like

mySearchTO.setBCol(resultSet.getString("B_COL"));
mySearchTO.setACol(resultSet.getString("A_COL")); 

in sql.

How to achieve this with JPA ?
Also, how can I write main query in JPA ?

I can not use Criteria Builder as I have to run my app on WSAD 6.1

The query which I am running is:

select s.aCol, s.bCol, s.cCol from MyEntity s  where s.cCol like 'abc' order by s.cCol asc

Above query is returning a List.

How to map it with my TO ?? I am trying

List<mySearchTO> myResult = new ArrayList<mySearchTO>();
myResult = myQuery.getResultList();

Where my TO class is a simple class with 3 properties (aCol, bCol and cCol) and getters and setters.

Error I am getting is

Exception thrown : java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.SummaryTO

But this is giving

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:00:52+00:00Added an answer on May 26, 2026 at 12:00 pm

    JPA has pagination support with the Query.setFirstResult and Query.setMaxResults methods. I don’t know how it translates in SQL with DB2, though, but it’s done in database (using rownum with Oracle, limit with MySQL, etc.)

    Just write your JPA query as you would do without pagination, and call these two methods, and Hibernate will generate the appropriate SQL query:

    select s.aCol, s.bCol, s.cCol from MyEntity s 
    where s.cCol like :pattern 
    order by s.cCol asc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below: string SQL = select * from + TableName; using
I have the below sql query to insert the records from a table. The
Consider the SQL query below: SELECT * FROM opening_hours WHERE week_day = WEEKDAY(NOW()) +
I have sql query like shown below the sql server says that their is
i have a sql query in asp.net SqlCommand QueidCmd = new SqlCommand(select scope_identity() from
I have the below SQL query: SELECT g.name AS gname, COUNT(u.id) AS noMembers, f.name
I currently have the following SQL Query: SELECT con_Content, cot_Name, pag_Name FROM [Page] inner
I have a SQL query which retrieve wall post list $qry=mysql_query(SELECT senderid,post,date FROM .post_table.
The sql injection will work only when my query looks like below sample SELECT
I have a problem with the SQL statement detailed below. The query returns the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.