Grails
  1. Grails
  2. GRAILS-6780

problems when using inheritance with abstract domain-classes

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Duplicate
    • Affects Version/s: 1.3.5, 1.3.6, 1.3.7, 1.3.8
    • Fix Version/s: 2.0 final
    • Component/s: Persistence
    • Labels:
      None
    • Environment:
      kubuntu 10.04, jbm 1.6.20, grails 1.3.5

      Description

      When having an inheritance structure similiar to the one in the attached project:

      Book extends Literature
      Magazine extends Literature

      Owner has reference to a Literature

      When the Literature Domain Class is abstract there are 2 Problems.

      • even if the it defines
        	static mapping = {
        		tablePerHierarchy false
        	}
        

        in the Mapping DSL it ignores it and adds the fields of Literature to the Tables of the Sub-Klasses.
        No Table for the abstract Litrature Class.
        Am I wrong in expecting it to behave similiar to the case the Literature wouldn't be abstract.

      • If I have a reference to such an abstract domain class from another domain class i get the following MappingException.

      Am I wrong in beliving this should be a possible implementation ?
      What is the right way to implement such a construct in Grails (SuperClass should not be instantiable but referenceable).

      I attached an simple made up sample project which comes up with the Exception on startup. You can either remove the abstract keyword from Literature or the Reference from Owner to Literature to make the app start.

      [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table owner refers to an unmapped class: library.Literature
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table owner refers to an unmapped class: library.Literature
      	at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
      	at grails.web.container.EmbeddableServer$start.call(Unknown Source)
      	at grails.web.container.EmbeddableServer$start.call(Unknown Source)
      	at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
      	at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
      	at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
      	at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
      	at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
      	at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
      	at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
      	at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
      	at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
      	at _GrailsRun_groovy$_run_closure8_closure14.doCall(_GrailsRun_groovy:263)
      	at _GrailsRun_groovy$_run_closure8_closure14.doCall(_GrailsRun_groovy)
      	at _GrailsPackage_groovy$_run_closure8.doCall(_GrailsPackage_groovy:299)
      	at _GrailsPackage_groovy$_run_closure8.call(_GrailsPackage_groovy)
      	at _GrailsRun_groovy$_run_closure8.doCall(_GrailsRun_groovy:245)
      	at RunApp$_run_closure1.doCall(RunApp.groovy:35)
      	at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
      	at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
      	at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
      	at gant.Gant.withBuildListeners(Gant.groovy:427)
      	at gant.Gant.this$2$withBuildListeners(Gant.groovy)
      	at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
      	at gant.Gant.dispatch(Gant.groovy:415)
      	at gant.Gant.this$2$dispatch(Gant.groovy)
      	at gant.Gant.invokeMethod(Gant.groovy)
      	at gant.Gant.executeTargets(Gant.groovy:590)
      	at gant.Gant.executeTargets(Gant.groovy:589)
      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table owner refers to an unmapped class: library.Literature
      	... 29 more
      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: An association from the table owner refers to an unmapped class: library.Literature
      	... 29 more
      Caused by: org.hibernate.MappingException: An association from the table owner refers to an unmapped class: library.Literature
      	... 29 more
      Application context shutting down...
      

        Activity

        Hide
        Zach Riggle added a comment -

        I am also running into this issue. Affects 1.3.4 as well.

        Show
        Zach Riggle added a comment - I am also running into this issue. Affects 1.3.4 as well.
        Hide
        Conny Kreyßel added a comment -

        Same here.

        Show
        Conny Kreyßel added a comment - Same here.
        Hide
        Graeme Rocher added a comment -

        The problems with abstract inheritance trees are planned to be fixed for 1.4

        Show
        Graeme Rocher added a comment - The problems with abstract inheritance trees are planned to be fixed for 1.4
        Hide
        Tom Crossland added a comment - - edited

        This is working fine in Grails 2.0.3. It would be very convenient to retrofit to 1.3.x until 2.x becomes a bit more stable. This looks like the fix:
        https://github.com/grails/grails-core/commit/25fcd322c256ddabd95f1cc5f54ebc67772ccc30#grails-hibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/GrailsDomainBinder.java

        Show
        Tom Crossland added a comment - - edited This is working fine in Grails 2.0.3. It would be very convenient to retrofit to 1.3.x until 2.x becomes a bit more stable. This looks like the fix: https://github.com/grails/grails-core/commit/25fcd322c256ddabd95f1cc5f54ebc67772ccc30#grails-hibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/GrailsDomainBinder.java
        Hide
        Graeme Rocher added a comment -

        This won't be back ported to 1.3.x, the 2.x line is already stable and being used by many users

        Show
        Graeme Rocher added a comment - This won't be back ported to 1.3.x, the 2.x line is already stable and being used by many users
        Hide
        Tom Crossland added a comment -

        No criticism intented, I'm one of the many users of 2.x and appreciate the improvements and the direction it's taking. But I don't believe 1.3 should be neglected just yet, there are many stable enterprise applications on 1.3. What's the criteria for including a fix in 1.3. The recent 1.3.9 release included only GRAILS-9027 (0 votes). Why not GRAILS-6780 (9 votes) and it's duplicates GRAILS-5356 (32 votes) and GRAILS-2583 (20 votes)?

        Show
        Tom Crossland added a comment - No criticism intented, I'm one of the many users of 2.x and appreciate the improvements and the direction it's taking. But I don't believe 1.3 should be neglected just yet, there are many stable enterprise applications on 1.3. What's the criteria for including a fix in 1.3. The recent 1.3.9 release included only GRAILS-9027 (0 votes). Why not GRAILS-6780 (9 votes) and it's duplicates GRAILS-5356 (32 votes) and GRAILS-2583 (20 votes)?
        Hide
        Graeme Rocher added a comment -

        GRAILS-6780 required a significant number of changes and represents a "new feature". Only small bug fixes with little chance of regression were applied to 1.3.x. In addition 1.3.9 is the last 1.3.x release, Grails 2.1 will be out of a few weeks and the focus of our development efforts in now on the 2.x line

        Show
        Graeme Rocher added a comment - GRAILS-6780 required a significant number of changes and represents a "new feature". Only small bug fixes with little chance of regression were applied to 1.3.x. In addition 1.3.9 is the last 1.3.x release, Grails 2.1 will be out of a few weeks and the focus of our development efforts in now on the 2.x line
        Hide
        Peter Ledbrook added a comment -

        And to clarify, GRAILS-9027 was technically a blocker but it simply wasn't marked as such. In fact, it was the sole reason for the 1.3.9 release.

        Show
        Peter Ledbrook added a comment - And to clarify, GRAILS-9027 was technically a blocker but it simply wasn't marked as such. In fact, it was the sole reason for the 1.3.9 release.

          People

          • Assignee:
            Unassigned
            Reporter:
            Konstantinos Kostarellis
          • Votes:
            9 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development