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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:40:30+00:00 2026-05-29T10:40:30+00:00

I have defined a JPA entity A with a @ManyToOne relationship to another JPA

  • 0

I have defined a JPA entity “A” with a @ManyToOne relationship to another JPA entity “B”.

@Entity
class A {

    String name;

    int sortOrder

    @ManyToOne
    B b;

}

This reference can be null or it can be populated. Now, I would like to query all the As and sort by B.name. Unfortunately, something like

find("order by B.name, sortOrder, name")

seems to drop any As such that (A.b = null). What is the best way to write this query?

I want all the As and I want them sorted by their B.name reference if it exists … lumping all those with no B property together.

  • 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-29T10:40:30+00:00Added an answer on May 29, 2026 at 10:40 am

    you need a left join.

    select a from A a left join a.b b order by b.name, a.sortOder, a.name
    

    or something like that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a JPA project. I have an ExportProfile object: @Entity public class
A date field in my entity class is defined as below: @Temporal(TemporalType.TIMESTAMP) @Column(name =
I defined a generator for a JPA class: <sequence-generator name=MY_SEQ allocation-size=-1 sequence-name=MY_SEQ initial-value=100000000 />
I have a Formula defined as: @Entity @Table(name = MyEntity) @org.hibernate.annotations.Table(appliesTo = MyEntity) public
Let's say I have two JPA entities: @Entity public class EntityA { @Id private
I have defined a tag with a CSS attribute overflow set to scroll. This
I have defined a class A and derived a new class B from A
I have defined my Enums like this. public enum UserType { RESELLER(Reseller), SERVICE_MANAGER(Manager), HOST(Host);
I have a class mapped as an Entity to persist it in a database.
I have the following JPA SqlResultSetMapping: @SqlResultSetMappings({ @SqlResultSetMapping(name=GroupParticipantDTO, columns={ @ColumnResult(name=gpId), @ColumnResult(name=gpRole), // @ColumnResult(name=gpRemarks) }

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.