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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:55:49+00:00 2026-06-03T03:55:49+00:00

I have an entity class that has an embedded object within it: @Entity public

  • 0

I have an entity class that has an embedded object within it:

@Entity
public class Flight implements Serializable {

    /// .... other attributes
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name = "value", column =
        @Column(name = "FLIGHT_TIME")),
        @AttributeOverride(name = "dataState", column =
        @Column(name = "FLIGHT_TIME_TYPE", length = 20))
    })
    private DateDataStateValue flightDate;
}

The DateDataStateValue is as follows:

@Embeddable
public class DateDataStateValue implements DataStateValue<Date>, Serializable {

    private static final long serialVersionUID = 1L;

    @Column(name = "DATASTATE")
    @Enumerated(value = EnumType.STRING)
    private final DataState dataState;

    @Column(name = "DATAVALUE")
    @Temporal(TemporalType.TIMESTAMP)
    private final Date value;
}

When performing a fetch of Flights from the database, using a CriteriaQuery, and creating an Order object on the time column:

Path<Flight> propertyPath = queryRoot.get("flightDate");
Order order = isAscending() ? criteriaBuilder.asc(propertyPath) :  criteriaBuilder.desc(propertyPath);

The ordering is not what I want. For instance, if the flight table has the following values:

Flight 1  | ESTIMATED | 1 Jan 2012
Flight 2  | ESTIMATED | 1 Jan 2011
Flight 3  | ACTUAL    | 1 Jan 2010
Flight 4  | ESTIMATED | 1 Jan 2009

The result of an ascending sort will be:

Flight 3  | ACTUAL    | 1 Jan 2010
Flight 4  | ESTIMATED | 1 Jan 2009
Flight 2  | ESTIMATED | 1 Jan 2011
Flight 1  | ESTIMATED | 1 Jan 2012

It appears that the default ordering of an @Embedded column is to use the natural ordering of the elements in the order in which they are named in the class. Ie DATASTATE first, then DATAVALUE second.

What I would like to do is whenever the sort property is flightDate, the ordering is the date first, then the state, ie:

Flight 4  | ESTIMATED | 1 Jan 2009
Flight 3  | ACTUAL    | 1 Jan 2010
Flight 2  | ESTIMATED | 1 Jan 2011
Flight 1  | ESTIMATED | 1 Jan 2012

Making the DateDataStateValue comparable doesn’t affect it, and @orderColumn/@OrderBy don’t seem to be the right thing for the job. Does anyone have any ideas?

Thanks in advance.

  • 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-03T03:55:50+00:00Added an answer on June 3, 2026 at 3:55 am

    I didn’t even know you could add an order by query on an embeddable property like this. But I wouldn’t rely on it, and simply add two orders to your query:

    Path<Flight> statePath = queryRoot.get("flightDate.dateState"); // or queryRoot.get("flightDate").get("dateState"): to be tested
    Path<Flight> valuePath = queryRoot.get("flightDate.value");
    Order[] orders;
    if (isAscending()) {
        orders = new Order[] {criteriaBuilder.asc(valuePath), criteriaBuilder.asc(statePath)  };
    }
    else {
        orders = new Order[] {criteriaBuilder.desc(valuePath), criteriaBuilder.desc(statePath)  
    }
    
    query.orderBy(orders);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an entity that has a ManyToMany relationship with itself: @Entity public class
I have an entity class that has 10 fields. I am using MS Validation
In my business model I have Entity class (IPoint interface ) that has a
I have a User class that has @Embedded a class Profile. How can I
I have an entity class that has a property with an underlying db column
I have a abstract entity class that 3 slightly different entities implements. In my
I have a domain class called Flight that represents a flight that has been
I would like to have a JPA Entity that has a GSon Object as
In the project I'm working on now, we have base Entity class that looks
I have an entity class Foo foo that contains Collection<Bar> bars . I've tried

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.