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

  • SEARCH
  • Home
  • 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 9143459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:02:00+00:00 2026-06-17T10:02:00+00:00

First I want to do a query like select count(*) from Post p where

  • 0

First I want to do a query like

"select count(*) from Post p where p.tag in (tagArray) "

where tagArray is “‘tag1′,’tag2’,’tag3′”.then I’d like to do a paginate query:

query.setFirstResult(int1).setMaxResult(int2);

I don’t know how to write this query. I searched the posts ,can’t find answers, so can anybody give me any advice? thanks.

  • 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-06-17T10:02:01+00:00Added an answer on June 17, 2026 at 10:02 am

    Thank you very much! Following your instruction, I’ve done it like this,a little complicated.

        public List<Post> findPostBySitePaged(Set sites, Page page) {
        List<Post> result = new ArrayList<Post>();
        if (sites == null || sites.size() == 0) return result;
    
        try {
            CriteriaBuilder builder = em.getCriteriaBuilder();
    
            CriteriaQuery<Long> cQuery = builder.createQuery(Long.class);
            Root<Post> root = cQuery.from(Post.class);
    
            CriteriaQuery<Long> select = cQuery.select(builder.count(root));
            select.where(root.get("site").in(sites));
    
            TypedQuery<Long> typedQuery = em.createQuery(select);
            Long t = typedQuery.getSingleResult();
    
            int tot = t.intValue() / page.getPageSize() + ((t.intValue() % page.getPageSize()) == 0 ? 0 : 1);
            page.setTotal(tot);
    
            CriteriaQuery<Post> criteriaQuery = builder.createQuery(Post.class);
            root = criteriaQuery.from(Post.class);
            criteriaQuery.select(root).where(root.get("site").in(sites)).orderBy(builder.desc(root.get("createDate")));
    
            TypedQuery<Post> postQuery = em.createQuery(criteriaQuery);
            postQuery.setFirstResult((page.getCurrent() - 1) * (page.getPageSize())).setMaxResults(page.getPageSize());
    
            result = postQuery.getResultList();
    
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query like: SELECT EXTRACT(WEEK FROM j.updated_at) as week, count(j.id) FROM jobs
Tried a query first like this SELECT * FROM CUSTOMER WHERE LEFT(NAME, 1) =
I have a simple query. Something like this: SELECT l.list_name, COUNT(order_id) FROM orders o
I have 2 tables which I want to query from. The first table (lets
I had a mysql query : Select count(*) as cnt from page06 where dl
I need to query a table like this: select phrase_id from direct_words where knowledge_id
I'm making a query to a MongoDB and I only want the first object.
I want to run a basic query, but return only the first ten rows
First I want to clearify that I mean by reverse engineering something like decompiling
I need to get the nid alone in this query. SELECT count(nid) as total,nid

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.