Grails
  1. Grails
  2. GRAILS-4089

Default Sort Order for associations causes java.sql.SQLException: Column not found

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Won't Fix
    • Affects Version/s: 1.1-RC1
    • Fix Version/s: 2.0-M2
    • Component/s: Persistence
    • Labels:
      None

      Description

      Given the following domain objects:

      class Parent {
          static hasMany = [ childs : Child ]
          static mapping = {
             childs sort:"s"
          }
      }
      
      class Child {
          static belongsTo = [Parent]
          String s
      }
      

      If I try to fetch Parents that have been created previously (through the bootstrap) or try to create (and then show) a Parent through the scaffolding, I get the following error:

      <snipped>
      Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: Parent.childs#2
      at C_dev_projects_testApp_testApp_grails_app_views_parent_show_gsp.run(C_dev_projects_testApp_testApp_grails_app_views_parent_show_gsp:37)
      Caused by: java.sql.SQLException: Column not found: CHILDS0_.S in statement [select childs0_.parent_childs_id as parent1_0_, childs0_.child_id as child2_0_ from parent_child childs0_ where childs0_.parent_childs_id=? order by childs0_.s]
      at org.hsqldb.jdbc.Util.throwError(Unknown Source)
      at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
      at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
      at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:185)
      at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:278)
      ... 1 more

      It seems to be trying to sort by the relation table (parent_child), where the 's' column does not exist, instead of the child table.

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Chris Brookes
          • Votes:
            37 Vote for this issue
            Watchers:
            37 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development