3 Replies Latest reply on Dec 8, 2006 8:56 AM by pmuir

    PostgreSQL collection problem

    sherkan777

      Hi all,
      Sorry for off topic, but those forum is most often searched:P

      My problem is with PostgreSQL db, previous I've used MySQL and everythink worked fine, but when I migrated to Postgre somethink wrong is going on with my collection.

      Let's see.
      Mother has childrens relation 1->n
      List myChildrens = new LinkedList();

      when i load mother object from db i have childrens positioned like I inserted them to db. (that is in mysql).
      example:
      Tom, Mike, Ann.

      After migration to postgresql, every time childrens are loaded different like in set collection.

      Example:
      1. Tom, Mike, Ann
      2. Mike, Ann, Tom etc.

      Anyone have an idea what should i check or what mechanism is responsible for loading objects from db?

      By the way mother object is loaded by Find method NOT query. (order by)
      Or maybe i made somethink wrong in my ds xml file with connection properties.

      Here's and some source code.
      MySQL DS:

      <datasources>
       <local-tx-datasource>
       <jndi-name>MyDS</jndi-name>
      
      <connection-url>jdbc:mysql://localhost:3306/myDB?useUnicode=true&amp;characterEncoding=latin2</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>root</user-name>
       <password>root</password>
       <exception-sorter-class-name>
       org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
       </exception-sorter-class-name>
      
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>
      


      and PostgreSQL ds:
      <datasources>
       <local-tx-datasource>
       <jndi-name>MyDS</jndi-name>
      
      <connection-url>jdbc:postgresql://localhost:5432/myDB</connection-url>
       <driver-class>org.postgresql.Driver</driver-class>
       <user-name>postgres</user-name>
       <password>root</password>
      
       <metadata>
       <type-mapping>PostgreSQL 8.2</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>
      


        • 1. Re: PostgreSQL collection problem
          askesis


          Nothing wrong with this: unless you specify an order in an SQL query, a
          database is allowed to return the result set in any order it likes. It
          is not even required to return the same result set in the same order if
          the query is rerun immediately after the first time.


          The fact that MySQL returns the records in insertion order is a
          "coincidence".

          --
          Groeten,

          Joost Kraaijeveld
          Askesis B.V.
          Molukkenstraat 14
          6524NB Nijmegen
          tel: 024-3888063 / 06-51855277
          fax: 024-3608416
          web: www.askesis.nl

          • 2. Re: PostgreSQL collection problem
            sherkan777

            So, can U tell me how to force DB to load objcets collection by find. method?
            Is any annotation for one to many relation mapping to specify loadings objcets from db?

            or, how U control loading objects from db (not using query and order by) but loadings them by find.(parent)?

            • 3. Re: PostgreSQL collection problem
              pmuir

              You need to use @OrderBy or @Sort on the collection (RTFM)