1

I have class RoomToday with some field. Inside this class there is a object of Room. I have no field name in RoomToday class.

class RoomToday {
    Room room;
    //other fields
}

class Room {
    String name;
    //
}

And i have repository RoomTodayrepository. Can i have method which sort by Room's name?

Something like that. This request must be in JPA repository:

List<RoomToday> findByIdInOrderByRoomNameAsc(Collection<UUID> id);
Krazim00da
  • 307
  • 1
  • 5
  • 14

1 Answers1

2

You need to make Room as @Embeddable,

class RoomToday {
    @Embedded
    Room room;
    //other fields
}
@Embeddable
class Room {
    String name;
    //
}

Then create a method in repository as below,

List<RoomToday> findByIdInOrderByRoomNameAsc(Collection<UUID> id);
Vikas
  • 6,868
  • 4
  • 27
  • 41