@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;
}
你能告诉我我应该怎么做才能让cluster.getPhrases()选择按频率排序的短语吗?
1条答案
按热度按时间bfrts1fy1#
尝试
请参见此处How do you order a oneToMany join table in hibernate criteria