Grails
  1. Grails
  2. GRAILS-7815

Domain object constructors effectively ignored

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-M1
    • Fix Version/s: 2.0-M2
    • Component/s: Persistence
    • Labels:
      None
    • Environment:
      Mac OS X 10.7

      Description

      I've been preferring to use the constructor of my domain objects to set default values for properties, but this stopped working with Grails 2.0. For instance with the following constructor, new User() returns an object without those fields set at all - they are all null.

      User() {
      role = Role.Diner
      enabled = true
      cashBalance = 0
      }

      If I println this.dump() within the constructor and do the same for the object returned from new User(), they have different object ids, so something funny is going on - i.e. my constructor is definitely executed, but it's as if a second object is then constructed (without my constructor called) which is the one actually returned.

      I can workaround this by directly assigning default values to the fields at the point of definition rather than in the constructor, but I believe this is a bug that should be fixed.

        Issue Links

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              Graeme Rocher
              Reporter:
              Sam Carr
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development