我在排序方面有一个小问题。在开始使用EntityGraph之后,它解决了我的问题,即结果重复等,并且一切正常,但是正在使用其ID对Jobs进行排序。
是否可以通过名称来进行可分页的排序作业?
我尝试使用Service.job.name,但是结果是相同的,我认为这只是图形的名称...
服务实体(其他字段缩写):
@NamedEntityGraph(name = "Service.job" ,attributeNodes = @NamedAttributeNode("jobs"))
@Entity
@Data
@Table(name = "service")
public class Service {
...
@ManyToMany(targetEntity = Job.class)
@JoinTable(name = "service_has_job",
joinColumns = { @JoinColumn(name = "service_id", referencedColumnName = "id")},
inverseJoinColumns = { @JoinColumn(name = "job_id", referencedColumnName = "id")}
)
private Set<Job> jobs = new HashSet<>();
...
}
带有覆盖的findAll的ServiceRepository:
@Repository
public interface ServiceRepository extends JpaRepository<Service, Long>, JpaSpecificationExecutor<Service> {
@Override
@EntityGraph(value = "Service.job" , type = EntityGraph.EntityGraphType.LOAD)
Page<Service> findAll(Specification<Service> spec, Pageable pageable);
}