hibernate没有正确加入表格

时间:2017-09-28 02:02:25

标签: postgresql hibernate spring-boot

我有两个表,ScheduleUserScheduleUserScheduleschedule_iduser_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。为什么?我似乎无法找到任何错误。

0 个答案:

没有答案