AppFuse
  1. AppFuse
  2. APF-1049

Hibernate returns repeat records when getAll

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0.2
    • Component/s: Persistence Layer
    • Labels:
      None
    • Environment:
      windows,struts2,hibernate,mysql

      Description

      I have a entity named salary.
      salary is oneToOne user.

      if a user has two roles,when I get all of salary,there will be one repeat record.
      if a user has three roles,when I get all of salary,there will be two repeat records.
      and so on.

      attachment is my demo project.

        Activity

        Hide
        ChenZhiguo added a comment -

        The hql is:
        select this_.id as id2_2_, this_.salary as salary2_2_, this_.userId as userId2_2_, user2_.id as id0_0_, user2_.account_expired as account2_0_0_, user2_.account_locked as account3_0_0_, user2_.address as address0_0_, user2_.city as city0_0_, user2_.country as country0_0_, user2_.postal_code as postal7_0_0_, user2_.province as province0_0_, user2_.credentials_expired as credenti9_0_0_, user2_.email as email0_0_, user2_.account_enabled as account11_0_0_, user2_.first_name as first12_0_0_, user2_.last_name as last13_0_0_, user2_.password as password0_0_, user2_.password_hint as password15_0_0_, user2_.phone_number as phone16_0_0_, user2_.username as username0_0_, user2_.version as version0_0_, user2_.website as website0_0_, roles3_.user_id as user1_4_,role4_.id as role2_4_, role4_.id as id1_1_, role4_.description as descript2_1_1_, role4_.name as name1_1_ from Salary this_ left outer join app_user user2_ on this_.userId=user2_.id left outer join user_role roles3_ on user2_.id=roles3_.user_id left outer join role role4_ on roles3_.role_id=role4_.id

        Show
        ChenZhiguo added a comment - The hql is: select this_.id as id2_2_, this_.salary as salary2_2_, this_.userId as userId2_2_, user2_.id as id0_0_, user2_.account_expired as account2_0_0_, user2_.account_locked as account3_0_0_, user2_.address as address0_0_, user2_.city as city0_0_, user2_.country as country0_0_, user2_.postal_code as postal7_0_0_, user2_.province as province0_0_, user2_.credentials_expired as credenti9_0_0_, user2_.email as email0_0_, user2_.account_enabled as account11_0_0_, user2_.first_name as first12_0_0_, user2_.last_name as last13_0_0_, user2_.password as password0_0_, user2_.password_hint as password15_0_0_, user2_.phone_number as phone16_0_0_, user2_.username as username0_0_, user2_.version as version0_0_, user2_.website as website0_0_, roles3_.user_id as user1_4_,role4_.id as role2_4_, role4_.id as id1_1_, role4_.description as descript2_1_1_, role4_.name as name1_1_ from Salary this_ left outer join app_user user2_ on this_.userId=user2_.id left outer join user_role roles3_ on user2_.id=roles3_.user_id left outer join role role4_ on roles3_.role_id=role4_.id
        Hide
        ChenZhiguo added a comment -

        If I use hql="from Salary", the hql will be:
        select salary0_.id as id2_, salary0_.salary as salary2_, salary0_.userId as userId2_ from Salary salary0_

        select user0_.id as id0_1_, user0_.account_expired as account2_0_1_, user0_.account_locked as account3_0_1_, user0_.address as address0_1_, user0_.city as city0_1_, user0_.country as country0_1_, user0_.postal_code as postal7_0_1_, user0_.province as province0_1_, user0_.credentials_expired as credenti9_0_1_, user0_.email as email0_1_, user0_.account_enabled as account11_0_1_, user0_.first_name as first12_0_1_, user0_.last_name as last13_0_1_, user0_.password as password0_1_, user0_.password_hint as password15_0_1_, user0_.phone_number as phone16_0_1_, user0_.username as username0_1_, user0_.version as version0_1_, user0_.website as website0_1_, roles1_.user_id as user1_3_, role2_.id as role2_3_, role2_.id as id1_0_, role2_.description as descript2_1_0_, role2_.name as name1_0_ from app_user user0_ left outer join user_role roles1_ on user0_.id=roles1_.user_id left outer join role role2_ on roles1_.role_id=role2_.id where user0_.id=?

        and so on.

        Show
        ChenZhiguo added a comment - If I use hql="from Salary", the hql will be: select salary0_.id as id2_, salary0_.salary as salary2_, salary0_.userId as userId2_ from Salary salary0_ select user0_.id as id0_1_, user0_.account_expired as account2_0_1_, user0_.account_locked as account3_0_1_, user0_.address as address0_1_, user0_.city as city0_1_, user0_.country as country0_1_, user0_.postal_code as postal7_0_1_, user0_.province as province0_1_, user0_.credentials_expired as credenti9_0_1_, user0_.email as email0_1_, user0_.account_enabled as account11_0_1_, user0_.first_name as first12_0_1_, user0_.last_name as last13_0_1_, user0_.password as password0_1_, user0_.password_hint as password15_0_1_, user0_.phone_number as phone16_0_1_, user0_.username as username0_1_, user0_.version as version0_1_, user0_.website as website0_1_, roles1_.user_id as user1_3_, role2_.id as role2_3_, role2_.id as id1_0_, role2_.description as descript2_1_0_, role2_.name as name1_0_ from app_user user0_ left outer join user_role roles1_ on user0_.id=roles1_.user_id left outer join role role2_ on roles1_.role_id=role2_.id where user0_.id=? and so on.
        Hide
        ChenZhiguo added a comment -

        and when I use hql=""from Salary" will resolve the problem.

        Show
        ChenZhiguo added a comment - and when I use hql=""from Salary" will resolve the problem.
        Hide
        Sharif Uddin added a comment -

        Here is a possible solution posted by me
        http://jira.springframework.org/browse/SPR-5007

        Show
        Sharif Uddin added a comment - Here is a possible solution posted by me http://jira.springframework.org/browse/SPR-5007
        Hide
        ChenZhiguo added a comment -

        Is this a good solution?

        Show
        ChenZhiguo added a comment - Is this a good solution?
        Hide
        Matt Raible added a comment -

        Fixed in 2.0.2 by adding getAllDistinct via APF-1013.

        Show
        Matt Raible added a comment - Fixed in 2.0.2 by adding getAllDistinct via APF-1013 .

          People

          • Assignee:
            Matt Raible
            Reporter:
            ChenZhiguo
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development