Home > Mobile >  Select phrases ordered by frequency
Select phrases ordered by frequency

Time:01-25

@Entity
@Table(name = "clusters", uniqueConstraints = {@UniqueConstraint(name = "unique_cluster_name",
        columnNames = {"clusterName"})})
@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ClusterEntity extends BaseEntity {
    @OneToMany(mappedBy = "cluster",
            cascade = CascadeType.REMOVE)
    private List<CorePhraseEntity> phrases = new ArrayList<>();
}
​
​
​
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "phrases", uniqueConstraints = {@UniqueConstraint(name = "unique_phrase",
        columnNames = {"phrase"})})
public class CorePhraseEntity extends BaseEntity implements Phraseable {
​
    private static final String URL_PREFIX = "/semantics/phrases/core/";
    @ManyToOne
    @JoinColumn(name = "cluster_id",
            nullable = false,
            foreignKey = @ForeignKey(name = "cluster_fk"))
    private ClusterEntity cluster;
​
    @NotNull
    @NotEmpty
    @Column(nullable = false,
            columnDefinition = "varchar(1000) default ''")
    private String phrase;
​
    @NotNull
    @Column(nullable = false,
            columnDefinition = "INTEGER DEFAULT -1")
    Integer frequency;
​
}

Could you tell me what should I do for cluster.getPhrases() to select phrases ordered by frequency?

CodePudding user response:

try

@OneToMany(mappedBy = "cluster", cascade = CascadeType.REMOVE)
@OrderBy("frequency")
private List<CorePhraseEntity> phrases = new ArrayList<>();

see here How do you order a oneToMany join table in hibernate criteria

  • Related