Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate中的HQL查询针对不同的用户选择相同的结果集_Hibernate_Hql_Jpql - Fatal编程技术网

Hibernate中的HQL查询针对不同的用户选择相同的结果集

Hibernate中的HQL查询针对不同的用户选择相同的结果集,hibernate,hql,jpql,Hibernate,Hql,Jpql,我在JPA存储库中创建了一个名为FindItemSyuser()的方法,并针对Item类开发了一个命名查询,如下所示: @NamedQuery(name = "Item.findItemsByUser", query = "SELECT i FROM Item i WHERE i.user=user order by id") 问题是,查询针对user_id=23和user_id=24输出相同的结果集,而在实际数据库中,针对user_id=24不存在任何项 下面是生成的SQL Hib

我在JPA存储库中创建了一个名为
FindItemSyuser()
的方法,并针对Item类开发了一个命名查询,如下所示:

@NamedQuery(name = "Item.findItemsByUser", 
    query = "SELECT i FROM Item i WHERE i.user=user order by id")
问题是,查询针对user_id=23和user_id=24输出相同的结果集,而在实际数据库中,针对user_id=24不存在任何项

下面是生成的SQL

Hibernate: select user0_.id as id1_11_, user0_.address_id as address_9_11_, user0_.contact_no as contact_2_11_, user0_.date_creation as date_cre3_11_, user0_.email as email4_11_, user0_.full_name as full_nam5_11_, user0_.is_active as is_activ6_11_, user0_.password as password7_11_, user0_.username as username8_11_ from users user0_ where user0_.username=? and user0_.password=?
Hibernate: select address0_.id as id1_0_0_, address0_.address as address2_0_0_, address0_.city_id as city_id3_0_0_, city1_.id as id1_2_1_, city1_.name as name2_2_1_, city1_.province_id as province3_2_1_, province2_.id as id1_7_2_, province2_.country_code as country_3_7_2_, province2_.name as name2_7_2_, country3_.code as code1_3_3_, country3_.name as name2_3_3_ from address address0_ left outer join city city1_ on address0_.city_id=city1_.id left outer join province province2_ on city1_.province_id=province2_.id left outer join country country3_ on province2_.country_code=country3_.code where address0_.id=?
Hibernate: select roles0_.user_id as user_id1_13_0_, roles0_.roles_id as roles_id2_13_0_, role1_.id as id1_8_1_, role1_.role_name as role_nam2_8_1_ from users_roles roles0_ inner join roles role1_ on roles0_.roles_id=role1_.id where roles0_.user_id=?
Hibernate: select supplier0_.id as id1_10_, supplier0_.name as name2_10_ from supplier supplier0_
23is the id of the user
Hibernate: select item0_.id as id1_4_, item0_.invoice_bill_no as invoice_2_4_, item0_.approved_by as approved3_4_, item0_.category_id as categor23_4_, item0_.cores as cores4_4_, item0_.date_approval as date_app5_4_, item0_.date_expiry as date_exp6_4_, item0_.date_indent as date_ind7_4_, item0_.date_issuance as date_iss8_4_, item0_.date_purchase as date_pur9_4_, item0_.hard_drive as hard_dr10_4_, item0_.license as license11_4_, item0_.location as locatio12_4_, item0_.manufacturer_id as manufac24_4_, item0_.model as model13_4_, item0_.price as price14_4_, item0_.processor_id as process25_4_, item0_.purchaser as purchas15_4_, item0_.ram as ram16_4_, item0_.recommended_by as recomme17_4_, item0_.ref_letter as ref_let18_4_, item0_.replacement_no as replace19_4_, item0_.section_id as section26_4_, item0_.serial_no as serial_20_4_, item0_.service_tag_no as service21_4_, item0_.supplier_id as supplie27_4_, item0_.user_id as user_id28_4_, item0_.vendor as vendor22_4_ from item item0_ where item0_.user_id=item0_.user_id order by item0_.id
Hibernate: select category0_.id as id1_1_0_, category0_.name as name2_1_0_ from category category0_ where category0_.id=?
Hibernate: select manufactur0_.id as id1_5_0_, manufactur0_.name as name2_5_0_ from manufacturer manufactur0_ where manufactur0_.id=?
Hibernate: select processor0_.id as id1_6_0_, processor0_.name as name2_6_0_ from processor processor0_ where processor0_.id=?
Hibernate: select section0_.id as id1_9_0_, section0_.name as name2_9_0_ from section section0_ where section0_.id=?
Hibernate: select user0_.id as id1_11_0_, user0_.address_id as address_9_11_0_, user0_.contact_no as contact_2_11_0_, user0_.date_creation as date_cre3_11_0_, user0_.email as email4_11_0_, user0_.full_name as full_nam5_11_0_, user0_.is_active as is_activ6_11_0_, user0_.password as password7_11_0_, user0_.username as username8_11_0_, address1_.id as id1_0_1_, address1_.address as address2_0_1_, address1_.city_id as city_id3_0_1_, city2_.id as id1_2_2_, city2_.name as name2_2_2_, city2_.province_id as province3_2_2_, province3_.id as id1_7_3_, province3_.country_code as country_3_7_3_, province3_.name as name2_7_3_, country4_.code as code1_3_4_, country4_.name as name2_3_4_ from users user0_ left outer join address address1_ on user0_.address_id=address1_.id left outer join city city2_ on address1_.city_id=city2_.id left outer join province province3_ on city2_.province_id=province3_.id left outer join country country4_ on province3_.country_code=country4_.code where user0_.id=?
2019-11-20 17:14:10.509  INFO 28324 --- [nio-8080-exec-1] p.g.dgip.controllers.MainPageController  : INFO:USER ID 23 LOGGED IN AT Wed Nov 20 17:14:10 PKT 2019

我不明白为什么它会针对不同的用户选择相同的结果集

问题只存在于查询中。我只需消除@NamedQuery(name=“Item.findItemsByUser”,Query=“从项目I中选择I,其中I.user=用户按id排序”),问题就消除了

您能否显示生成的SQL查询以及
用户
实体代码?请查看生成的sqlI我猜问题出在这里
i.User=User
,因此您得到了
。。其中item0\u0.user\u id=item0\u0.user\u id