查询问题卡了一个多个小时,特来求助 。
两张表 : User 表 和 Order 表。 User 有多个 Order。 Order 只能有一个 User。
代码如下图 : User 表 :
Order 表 :
需求 : 根据 User 的 id 返回 User 对象 。
我使用的方法 : 直接通过 jpa 查询
Optional<User> optiOnal= userDao.findById(userId); 遇到的问题 : 查询过程,直接报错 :
Hibernate show sql :
select user0_.id as id1_1_0_, user0_.age as age2_1_0_, user0_.name as name3_1_0_, user0_.sex as sex4_1_0_, customer1_.user_id as user_id2_0_1_, customer1_.order_id as order_id1_0_1_, customer1_.order_id as order_id1_0_2_, customer1_.user_id as user_id2_0_2_ from user user0_ left outer join order customer1_ on user0_.id=customer1_.user_id where user0_.id=? > 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order customer1_ on user0_.id=customer1_.user_id where user0_.id=?' at line 7 > Time: 0s 