Hibernate query gives same record multiple times

前端 未结 6 605
再見小時候
再見小時候 2021-02-07 06:30

I am working on hibernate in eclipse. I am executing simple \'From\' query. Here is the code

  List list = sess1.createQuery(\"From Myview\").list();
    System.         


        
相关标签:
6条回答
  • 2021-02-07 07:10

    You should use the distinct keyword to filter the same result.

    0 讨论(0)
  • 2021-02-07 07:23

    If you have association in the mapping then check if fetch=FetchType.EAGER. If yes then use other fetch type or fetchMode.

    0 讨论(0)
  • 2021-02-07 07:24

    Put the objects returned by Hibernate to a LinkedHashSet and return the LinkedHashSet.

    0 讨论(0)
  • 2021-02-07 07:26

    This happens when the id element in your hbm file is not a PK in your DB table. Hibernate treats all rows with the same ID as the same object.

    Either change your id element to point to a PK column or use the composite-id element in case your table only has a composite primary key.

    0 讨论(0)
  • 2021-02-07 07:27

    Your entity Myview have to implement java.io.Serializable interface

    0 讨论(0)
  • 2021-02-07 07:28

    Are you sure that the table is correctly filled? try :

    List list = sess1.createQuery("SELECT * FROM Myview").list();
    

    futhermore, you are getting this list from a view? are you sure that you made this view correctly?

    0 讨论(0)
提交回复
热议问题