Grails
  1. Grails
  2. GRAILS-4256

mapping composite id as foreign key in a one-to-many association

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Duplicate
    • Affects Version/s: 1.1
    • Fix Version/s: 1.2.3, 1.3.2
    • Component/s: Commons
    • Labels:
      None
    • Environment:
      grails 1.1/windows

      Description

      I found this problem in mapping a composite id as foreign key in a one-to-many association:

      here is my class with composite id:

      class IntCau implements Serializable {
      	static mapping = {
      		table 'int_cau'
      		version false
                     id composite: ['c1', 'c2', 'c3'], generator: "assigned"
              }
              int c1
      	char c2
      	int c3
              static HasMany = [attScheds: AttSched, attProgrs: AttProgr]
      	static mappedBy = [attScheds: 'causale', attProgrs: 'causale']
      }
      

      this is in relation one-to-many with two other classes (which have pretty much the same code):

      class AttProgr {
      	static mapping = {
      		table 'att_sched'
      		version false
      		columns {
      			causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau']
                      }
                      IntCau causale
      }
      

      i get this error:

      Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.InvalidPropertyException: No property found for name [attProgrs] for class [class IntCau]

      so i insert the following declaration in the IntCau class:

      List<AttSched> attScheds
      List<AttProgr> attProgrs
      

      and now the error became:

      Invocation of init method failed; nested exception is org.hibernate.MappingException: Foreign key (FKE0C5693A41F5AA0A:att_progr [c1_int_cau, c2_int_cau, c3_int_cau,int_cau_c1,int_cau_c2,int_cau_c3])) must have same number of columns as the referenced primary key (int_cau [c1,c2,c3])

      What's wrong? If i do the same on a class with simple foreign key all works! It's a bug?
      I found a similar issue marked as resolved but my my problem still remain in new release 1.1
      (http://jira.codehaus.org/browse/GRAILS-3506)

      I also try to define the class in this way:

      class AttProgr {
      	static mapping = {
      		table 'att_sched'
      		version false
      		columns {
      			causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau']
                              int_cau_c1 column: 'c1_int_cau'
      			int_cau_c2 column: 'c2_int_cau'
      			int_cau_c3 column: 'c3_int_cau'
                      }
                      IntCau causale
                      int int_cau_c1
      	        char int_cau_c2
      	        int int_cau_c3
      }
      

      compiling is ok, but in the browser i found the same exception.

      and now the problem is in columns mapping:

      Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsDomainException: Error evaluating ORM mappings block for domain [AttProgr]: No such property: causale for class: GroovyObjectSupport_groovyProxy

        Activity

        Hide
        valentina ceruti added a comment -

        Sorry the last row:
        columns

        { causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau'] int_cau_c1 column: 'c1_int_cau' int_cau_c2 column: 'c2_int_cau' int_cau_c3 column: 'c3_int_cau' }

        is:

        columns

        { causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau'] int_cau_c1 column: 'c1_int_cau' int_cau_c2 column: 'c2_int_cau' int_cau_c3 column: 'c3_int_cau' }
        Show
        valentina ceruti added a comment - Sorry the last row: columns { causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau'] int_cau_c1 column: 'c1_int_cau' int_cau_c2 column: 'c2_int_cau' int_cau_c3 column: 'c3_int_cau' } is: columns { causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau'] int_cau_c1 column: 'c1_int_cau' int_cau_c2 column: 'c2_int_cau' int_cau_c3 column: 'c3_int_cau' }
        Hide
        Graeme Rocher added a comment -

        There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3

        for 1.2 final only issues considered blocking will now be fixed

        Show
        Graeme Rocher added a comment - There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3 for 1.2 final only issues considered blocking will now be fixed
        Hide
        Graeme Rocher added a comment -

        Duplicates GRAILS-6349

        Show
        Graeme Rocher added a comment - Duplicates GRAILS-6349
        Hide
        keith Albert added a comment -

        This does not duplicate GRAILS 6349, since this is a one-to-many issue. The patched code only handles for manyToMany, or manyToOne (see patch 'snip' below. Please fix for one-to-many associations.

        if ((shouldCollectionBindWithJoinColumn(property) && hasCompositeIdentifier(mapping)) ||
        (hasCompositeIdentifier(mapping) && property.isManyToMany()))

        { CompositeIdentity ci = (CompositeIdentity) mapping.getIdentity(); bindCompositeIdentifierToManyToOne(property, key, ci, refDomainClass, EMPTY_PATH); }

        else

        { bindSimpleValue(property, null, key, EMPTY_PATH, mappings); }
        Show
        keith Albert added a comment - This does not duplicate GRAILS 6349, since this is a one-to-many issue. The patched code only handles for manyToMany, or manyToOne (see patch 'snip' below. Please fix for one-to-many associations. if ((shouldCollectionBindWithJoinColumn(property) && hasCompositeIdentifier(mapping)) || (hasCompositeIdentifier(mapping) && property.isManyToMany())) { CompositeIdentity ci = (CompositeIdentity) mapping.getIdentity(); bindCompositeIdentifierToManyToOne(property, key, ci, refDomainClass, EMPTY_PATH); } else { bindSimpleValue(property, null, key, EMPTY_PATH, mappings); }

          People

          • Assignee:
            Burt Beckwith
            Reporter:
            valentina ceruti
          • Votes:
            16 Vote for this issue
            Watchers:
            13 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development