I have two classes in my spring application:
@Entity
@Table(name = "events")
public class Event {
@Id
@GeneratedValue
private long id;
@ManyToOne
@JoinColumn(name = "venue_fk")
private Venue venue;
// Setters, getters...
}
and
@Entity
@Table(name = "venues")
public class Venue {
@Id
@GeneratedValue
private long id;
private String name;
@OneToMany
private Set<Event> events = new HashSet<>();
// Setters, getters...
}
The thing I want to do is to write a method in VenueService that returns Iterable<Venue>
and venue objects appear in this Iterable based on how many events they have (DESC) and then venue name(ASC), the more events one venue has, the earlier it appears.
E.g. I have three venues, venueA has 3 events registered with it, venueB has 3 events registered with it, and venueC has 4 events registered with it, then the method findAllVenuesByNoOfEvents()
should return Iterable<Venue>
in the order venueC, venueA, venueB.
I'm new to spring and I'm really don't know how to do this, thanks in advance.