Код: Выделить всё
@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// other fields
@ElementCollection
@CollectionTable(name = "studentImages")
@MapKeyColumn(name = "file_name")
@SortComparator(reverseSort.getClass()) // Error: Attribute value must be a constant
@Column(name = "img_desc")
private Map images = new TreeMap();
private static Comparator reverseSort = Comparator.reverseOrder();
}
- Избавьтесь от «Значение атрибута аннотации» должно быть сообщением с постоянным выражением» [дубликат]
- Как передать значение аннотации из константного java
Код: Выделить всё
@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// other fields
@ElementCollection
@CollectionTable(name = "studentImages")
@MapKeyColumn(name = "file_name")
@SortComparator(ReverseStringComparator.class) // Is this a compile time constant?
@Column(name = "img_desc")
private Map images = new TreeMap();
private class ReverseStringComparator implements Comparator {
@Override
public int compare(String o1, String o2) {
return o2.compareTo(o1);
}
}
}
Также , есть ли другой способ, кроме определения и использования здесь внутреннего класса (с использованием @SortComparator)?
Подробнее здесь: https://stackoverflow.com/questions/792 ... e-sortedco
Мобильная версия