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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:06:06+00:00 2026-05-23T14:06:06+00:00

I have two classes Course and Student . Student class use firstName and lastName

  • 0

I have two classes Course and Student. Student class use firstName and lastName as the composite-key. I want to use @OrderBy("firstName ASC") in Course class, but there is an error “property from @OrderBy clause not found: Student.firstName”.

How can I sort on one of the composite keys (such as firstName)?

public class Course{
    @OneToMany(mappedBy="course")
    @OrderBy("firstName ASC")  
    // Error: property from @OrderBy clause not found: Student.firstName, why?
    private List<Student> students;
.....
}


public class Student{
    @Id
    @Column(name="first_name")
    private String firtName;
    @Id
    @Column(name="last_name")
    private String lastName;

    @ManyToOne
    @JoinColumn(name="course_id")
    private Course course;
.....
}
  • 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-23T14:06:06+00:00Added an answer on May 23, 2026 at 2:06 pm

    You misspelled it to, firtName — notice s is missing. Fix that and things will be fine, most likely.

    [Edited]

    In case it is still not working. Try to replace this by @EmbeddedId, instead. Like below,

    public class Student implements Serializable{
        @EmbeddedId
        private StudentPK name;
    
        @ManyToOne
        @JoinColumn(name="course_id")
        private Course course;
        .....
    
        @Embeddable
        public static class StudentPK implements Serializable {
            @Column(name="first_name")
            private String firtName;
    
            @Column(name="last_name")
            private String lastName;
    
            ....
        }
    }
    

    Then it should work using,

    public class Course{
        @OneToMany(mappedBy="course")
        @OrderBy("name.firstName ASC")  
        private List students;
        .....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, and want to include a static instance of one class
Suppose I have two classes: public class Student { public int Id {get; set;}
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two classes: Action and MyAction . The latter is declared as: class
I have two classes, Portfolio, and PortfolioImage. class PortfolioImage(models.Model): portfolio = models.ForeignKey('Portfolio', related_name='images') ...
I have two classes, Class A and Class B, both of them are subclasses
I have two classes in two files in a class library project, they are:
I have two classes, Student and Teacher, Student has one concrete method: takeCourse; Teacher
I have two classes in a many-to-many relationship, but only one of them have

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.