我有用户和任务。每个用户可以有多组任务,反之亦然。我调用包含在任务“成员”中的用户,但我没有成员实体,它是隐式的并通过注释@JoinTable(name = "member"...
声明。代码:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
private int id;
@ManyToMany
@JoinTable(name = "member", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "task_id"))
private Set<Task> tasks = new HashSet<>();
}
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
private int id;
@ManyToMany(mappedBy = "tasks")
private Set<User> users = new HashSet<>();
private Calendar initialDate;
private Calendar finalDate;
}
我的问题出现在JPQL查询中,因为我没有成员真正的bean(@Entity注释和东西)我无法在我的存储库上做任何事情(假设我和成员实体映射用户和任务) :
FROM User u
WHERE NOT EXISTS
(
FROM Member m WHERE m.task.finalDate >= :inicial AND m.task.finalDate <= :final
AND m.user.id = u.id//Member here is a hipotetical/nonexistent entity
)
使用JPQL / HQL进行此查询的任何方式或者我需要回退到本机sql查询? TY
答案 0 :(得分:0)
我不认为您提供的示例需要引用成员实体(如果存在)。你可能会做类似的事情:
from User u INNER JOIN u.tasks t WHERE t.finalData < :initial OR t.finalDate > :final