I have to create a company object in Java with a series of attributes. One of them is the size that comes to me in String and has this format
- 1-10
- 11-50
- 51-200
- 1000-5000
When making a query in the repository to return a list of companies ordered by size in ascending order, what it does is consider that 1000 goes before 11. I understand that since the second number is smaller than the second number of the second number , is the logic that works.
@Entity (name="company")
@Getter
@Setter
@ToString
``public class Company {
@Id
@Column(name = "id", nullable = false)
private String id;
private String website;
private String name;
@Digits(integer = 4, fraction = 0)
private Integer founded;
private String size;
private String locality;
private String region;
private String country;
private String industry;
@Column(name="linkedin_url")
private String linkedinUrl;
public Company(String id, String website, String name, Integer founded, String size, String locality, String region, String country, String industry, String linkedinUrl) {
this.id = id;
this.website = website;
this.name = name;
this.founded = founded;
this.size = size;
this.locality = locality;
this.region = region;
this.country = country;
this.industry = industry;
this.linkedinUrl = linkedinUrl;
}
public Company() {
}
}
@Query("select c from company c order by c.size")
List<Company> findByOrderBySizeAsc();