我有两个表,Schedule
和UserSchedule
。 UserSchedule
列schedule_id
和user_id
。我想做的是这样的select s from schedule s join user_schedule us on s.id = us.schedule_id where us.user_id = ?
。如果我直接将此查询运行到db,这将按预期工作。
Schedule
实体有userSchedule
和所有其他必要信息
@Setter
@Getter
@JoinColumn(name = "id", referencedColumnName = "schedule_id")
@OneToOne
private UserSchedule userSchedule;
我有@Query("select s from Schedule s join s.userSchedule")
和hibernate创建
select schedule0_.id as id1_10_, schedule0_.created_at as created_2_10_, schedule0_.end_date as end_date3_10_, schedule0_.end_time as end_time4_10_, schedule0_.frequency as frequenc5_10_, schedule0_.frequency_val as frequenc6_10_, schedule0_.is_active as is_activ7_10_, schedule0_.start_date as start_da8_10_, schedule0_.start_time as start_ti9_10_, schedule0_.updated_at as updated10_10_, schedule0_.description as descrip11_10_, schedule0_.lat as lat12_10_, schedule0_.lon as lon13_10_, schedule0_.project_id as project15_10_, schedule0_.title as title14_10_, (select v.status from voucher v where v.schedule_id = schedule0_.id) as formula1_ from schedule schedule0_ inner join user_schedule userschedu1_ on schedule0_.id=userschedu1_.id limit ?
查询on schedule0_.id=userschedu1_.id
的最后一部分应该是我认为的on schedule0_.id=userschedu1_.schedule_id
。为什么?我似乎无法找到任何错误。