Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select phrases ordered by frequency

@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?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading