我有两个实体类USER和TRAININGROLE,如下所示
USER(id,csl,fullname,email) - > id - long,其他字符串
TRAININGROLE(id,role) - > role是String,id是Long
我有Session.java实体类,如下所示
@Id @GeneratedValue private long id; @JoinTable(name="session_user", joinColumns = @JoinColumn(name="session_id"), inverseJoinColumns = @JoinColumn(name="trainingRole_id")) @MapKeyJoinColumn(name="user_id") @ManyToMany private Map<User, TrainingRole> users = new HashMap<User, TrainingRole>(); private Date start; private Date end;
我必须查询Session类以查找对特定会话具有特定培训角色的用户。所以我将会话ID和trainingrole对象传递给查询方法。错误的查询在下面..
public final static String FIND_TRAINER_FOR_SESSION = "SELECT DISTINCT users " + "FROM Session s join s.users users where( :trainingRole in elements(s.users) and s.id = :sid )"; @Query(FIND_TRAINER_FOR_SESSION) List<User> findTrainersForSessions(@Param("trainingRole") TrainingRole trainingRole,@Param("sid") Long sid);
请帮我纠正上述问题,以获得具有特定会话特定培训角色的用户。
还有一件事......我正在使用JPAReposotiry进行查询..
@Repository
public interface SessionRepository extends JpaRepository<Session, Long>{
}