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 8023569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:35:51+00:00 2026-06-04T22:35:51+00:00

I have a table that contains the following columns: @Column(name=CTDESTATUS) private String status; @Column

  • 0

I have a table that contains the following columns:

@Column(name="CTDESTATUS")
private String status;
@Column (name= "CTDEMESSAGE")
private String message;
@Temporal(TemporalType.TIMESTAMP)
@Column (name = "CTDTDATE")
private Date date;
@Column (name = "CTCDSERVICEID")
private String serviceId;

I need to build a query that returns the last n rows added to database, grouped by serviceId, where each row is the older one that contains one of the following status:

START or RUNNING or PAUSED or END_ERROR or END_SUCCESS

And sort the result by date descending.
I’m not familiar with the Eclipselink API, and I want something like that:

ExpressionBuilder builder = new ExpressionBuilder();
Expression exStatus1 = builder.get("status").equal("START");
Expression exStatus2 = builder.get("status").equal("RUNNING");
Expression exStatus3 = builder.get("status").equal("PAUSED");
Expression exStatus4 = builder.get("status").equal("END_ERROR");
Expression exStatus5 = builder.get("status").equal("END_SUCCESS");
Expression exStatus = (exStatus1).or(exStatus2).or(exStatus3).or(exStatus4).or(exStatus5);
Expression exGroup = builder.get("serviceId").distinct();
Expression exOrder = builder.get("date").descending();
ReadAllQuery query = new ReadAllQuery();
query.setReferenceClass(Notification.class);
query.setSelectionCriteria(exStatus);
query.addDescendingOrdering("date");
query.setMaxRows(n);

Someone can help me?

  • 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-04T22:35:52+00:00Added an answer on June 4, 2026 at 10:35 pm

    It should be something like this. I haven’t tried it on the IDE so it may have some errors, but should get you started.

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Notification> cq = criteriaBuilder.createQuery(Notification.class);
    Metamodel m = entityManager.getMetamodel();
    EntityType<Notification> Notification_ = m.entity(Notification.class);
    
    Root<Notification> root = cq.from(Notification_);
    
    Expression<String> exp1 = criteriaBuilder.upper(root.<String>get("status"));
    
    Predicate predicate1 = criteriaBuilder.like(emp1, "START");
    Predicate predicate2 = criteriaBuilder.like(emp1, "PAUSED");
    Predicate predicate3 = criteriaBuilder.like(emp1, "RUNNING");
    Predicate predicate4 = criteriaBuilder.like(emp1, "END_ERROR");
    Predicate predicate5 = criteriaBuilder.like(emp1, "END_SUCCESS");
    
    Predicate predicate = criteriaBuilder.or(predicate1, predicate2, predicate3, predicate4, predicate5)
    cq.where(predicate);
    cq.orderBy(criteriaBuilder.desc(root.get("date")));
    
    Query query = entityManager.createQuery(cq);
    query.setMaxResults(n);
    return query.getResultList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following requirement. I have a table with a column that contains
I have the following table that contains checkboxes in each row. When checkbox status
I have a table, Orgs, that contains the following data: ID Name AddressID 0
I have a lookup table that contains these columns: id, name, value, colx, coly
I have a table in SQL Server that contains the following columns : Id
I have one table with name CateringPurchaseOrder. That table contains one column with name
I have a database table (ff_projections) that contains the following fields: ID Player Position
I have a table that contains several thousand rows, having a Varchar column that
Should a database table that contains two columns that are foreign keys have a
I have following query select * from table1 if table1 contains text type column/columns

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.