facebook

HIBERNATE Does NOT Order Property Sets by ID?

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #298048 Reply

    I use Hibernate with Java.

    Hello I have two tables which are associated with foreign keys.

    Table: country
    Fields: ID, Name
    POJO class name : Country
    POJO class properties: id, name, cities

    Table: city
    Fields: ID, Name, CountryID
    POJO class name : Country

    Then I use “hibernate reverse engineering” of MyEclipse. It creates DAOs, abstracts and pojo classes automatically.

    Everything works very well. When I request a Country object, Hibernate retrieves it and fills the property “cities” with cities which has CountryID as country.id.

    Still everything fine but when I list “cities” property (java Set type), then print out IDs of all cities I got this unordered list:

    ID: 5
    ID: 1
    ID: 4
    ID: 2

    I don’t know where should I edit to get an ID ordered cities when I obtained Country instances from CountryDAO class.

    Please help me ASAP! :'(

    #298150 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development.

    #298151 Reply

    Loyal Water
    Member

    The “Order By” clause in the generated HQL *might* do it.. Sets and HashSets are not guaranteed to be ordered, and that is what our tool generates for the collection type.

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: HIBERNATE Does NOT Order Property Sets by ID?

You must be logged in to post in the forum log in