我有两个实体(工作,个人资料)。作品有两个配置文件字段(创建者,受让人)。 我从Spring数据jpa中获得了带有自定义查询(hql)的CrudRepository,在该查询中,我需要检索具有指定配置文件ID(创建者或工作人员)的所有作品,并仅加入不等于指定配置文件ID的那些配置文件。
public class Work {
@Id
private String id;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "created_by_id", updatable = false, nullable = false, insertable = false)
private Profile createdBy;
@Column(name = "created_by_id", updatable = false, nullable = false)
private String createdById;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "assignee_id", updatable = false, insertable = false)
private Profile assignee;
@Column(name = "assignee_id")
private String assigneeId;
}
class Profile {
@Id
private String id;
private String name;
}
public interface WorkRepository extends CrudRepository<Work, String> {
@Query("SELECT d, (CASE WHEN d.createdById = :profileId THEN d.assignee ELSE d.createdBy END) FROM Dialog d JOIN FETCH d.assignee JOIN FETCH d.createdBy WHERE d.profileId = :profileId OR d.creatorId = :profileId")
List<Dialog> findAllByUserId(@Param("profileId") String profileId);
}
我希望只收到一个热切获取一个配置文件的对话框,但是却同时获取了这两个配置文件,由于性能不好。