Grails
  1. Grails
  2. GRAILS-7200

Validation is failing when id generator is 'sequence' and save(validate: true) got called

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.3.6
    • Fix Version/s: None
    • Component/s: Persistence
    • Labels:
      None
    • Environment:
      Linux; Java 6; Grails 1.3.6.

      Description

      save(validate: true) fails for some domain classes using generator: 'sequence'. I've attached a test app.

      http://grails.1312388.n4.nabble.com/GORM-generator-sequence-and-save-validate-true-td3243226.html

      The highlighting points are:

      == devDB.script ==
      CREATE SEQUENCE SOME_SEQUENCE AS INTEGER START WITH 1
      CREATE MEMORY TABLE _SOME_OBJECT(CUSTOM_ID BIGINT NOT NULL PRIMARY
      KEY,SOME_TEXT VARCHAR(255))

      == grails-app/domain/test_seq_val/SomeObject.groovy ==

      class SomeObject {
      
         static mapping = {
           table '_some_object'
           id name: 'customId', generator: 'sequence', params: [sequence:
      'some_sequence']
         }
      
         // (...)
         Long customId
         // (...)
      }
      

      == grails-app/conf/BootStrap.groovy ==

           SomeObject.withTransaction {
             def s = new SomeObject()
             s.save(validate: false, flush: true)
           }
      
           SomeObject.withTransaction {
             def s = new SomeObject()
             s.save(validate: true, flush: true)
           }
      

      The second save fails because s.customId is null, but its value is
      retrieved from a sequence...
      Is this the expected behavior? Am i missing something? Should i raise a
      JIRA or is this a Hibernate bug? To me (if i've written everything
      properly) it seems that validation should occurs after sequence value
      has been retrieved or it should skip id validation.

      Thanks.

      Best regards,

      Daniel.

      Welcome to Grails 1.3.6 - http://grails.org/
      Licensed under Apache Standard License 2.0
      Grails home is set to: /usr/local/devel/grails-1.3.6

      Base Directory: /tmp/test_seq_val
      Resolving dependencies...
      Dependencies resolved in 580ms.
      Running script /usr/local/devel/grails-1.3.6/scripts/RunApp.groovy
      Environment set to development
      [delete] Deleting directory /home/daniel/.grails/1.3.6/projects/test_seq_val/tomcat
      Running Grails application..
      2011-01-27 19:10:08,896 [main] DEBUG jdbc.ConnectionManager - opening JDBC connection
      2011-01-27 19:10:08,932 [main] DEBUG jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
      2011-01-27 19:10:08,932 [main] DEBUG hibernate.SQL - call next value for some_sequence
      2011-01-27 19:10:08,935 [main] DEBUG jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
      2011-01-27 19:10:08,946 [main] DEBUG jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
      2011-01-27 19:10:08,946 [main] DEBUG hibernate.SQL - insert into _some_object (some_text, custom_id) values (?, ?)
      2011-01-27 19:10:08,946 [main] TRACE type.StringType - binding null to parameter: 1
      2011-01-27 19:10:08,946 [main] TRACE type.LongType - binding '1' to parameter: 2
      2011-01-27 19:10:08,946 [main] DEBUG jdbc.AbstractBatcher - Executing batch size: 1
      2011-01-27 19:10:08,947 [main] DEBUG jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
      2011-01-27 19:10:08,948 [main] DEBUG jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
      2011-01-27 19:10:08,948 [main] DEBUG jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
      2011-01-27 19:10:08,948 [main] DEBUG jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
      2011-01-27 19:10:08,952 [main] DEBUG jdbc.ConnectionManager - opening JDBC connection
      2011-01-27 19:10:09,029 [main] DEBUG jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
      2011-01-27 19:10:09,030 [main] DEBUG jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
      2011-01-27 19:10:09,030 [main] DEBUG jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
      2011-01-27 19:10:09,036 [main] ERROR context.GrailsContextLoader - Error executing bootstraps: Validation Error(s) occurred during save():

      • Field error in object 'test_seq_val.SomeObject' on field 'customId': rejected value [null]; codes [test_seq_val.SomeObject.customId.nullable.error.test_seq_val.SomeObject.customId,test_seq_val.SomeObject.customId.nullable.error.customId,test_seq_val.SomeObject.customId.nullable.error.java.lang.Long,test_seq_val.SomeObject.customId.nullable.error,someObject.customId.nullable.error.test_seq_val.SomeObject.customId,someObject.customId.nullable.error.customId,someObject.customId.nullable.error.java.lang.Long,someObject.customId.nullable.error,test_seq_val.SomeObject.customId.nullable.test_seq_val.SomeObject.customId,test_seq_val.SomeObject.customId.nullable.customId,test_seq_val.SomeObject.customId.nullable.java.lang.Long,test_seq_val.SomeObject.customId.nullable,someObject.customId.nullable.test_seq_val.SomeObject.customId,someObject.customId.nullable.customId,someObject.customId.nullable.java.lang.Long,someObject.customId.nullable,nullable.test_seq_val.SomeObject.customId,nullable.customId,nullable.java.lang.Long,nullable]; arguments [customId,class test_seq_val.SomeObject]; default message [Property [ {0}] of class [{1}] cannot be null]

        grails.validation.ValidationException: Validation Error(s) occurred during save():
        - Field error in object 'test_seq_val.SomeObject' on field 'customId': rejected value [null]; codes [test_seq_val.SomeObject.customId.nullable.error.test_seq_val.SomeObject.customId,test_seq_val.SomeObject.customId.nullable.error.customId,test_seq_val.SomeObject.customId.nullable.error.java.lang.Long,test_seq_val.SomeObject.customId.nullable.error,someObject.customId.nullable.error.test_seq_val.SomeObject.customId,someObject.customId.nullable.error.customId,someObject.customId.nullable.error.java.lang.Long,someObject.customId.nullable.error,test_seq_val.SomeObject.customId.nullable.test_seq_val.SomeObject.customId,test_seq_val.SomeObject.customId.nullable.customId,test_seq_val.SomeObject.customId.nullable.java.lang.Long,test_seq_val.SomeObject.customId.nullable,someObject.customId.nullable.test_seq_val.SomeObject.customId,someObject.customId.nullable.customId,someObject.customId.nullable.java.lang.Long,someObject.customId.nullable,nullable.test_seq_val.SomeObject.customId,nullable.customId,nullable.java.lang.Long,nullable]; arguments [customId,class test_seq_val.SomeObject]; default message [Property [{0}

        ] of class [

        {1}

        ] cannot be null]

      at BootStrap$_closure1_closure4.doCall(BootStrap.groovy:13)
      at $Proxy10.doInTransaction(Unknown Source)
      at BootStrap$_closure1.doCall(BootStrap.groovy:11)
      at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:251)
      at grails.util.Environment.executeForEnvironment(Environment.java:244)
      at grails.util.Environment.executeForCurrentEnvironment(Environment.java:220)
      at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
      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 RunApp$_run_closure1.doCall(RunApp.groovy:33)
      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)
      Application context shutting down...
      Application context shutdown.

      1. test_seq_val.tar.gz
        175 kB
        Daniel Henrique Alves Lima

        Activity

        Daniel Henrique Alves Lima created issue -
        Contegix Support made changes -
        Field Original Value New Value
        Project Import Thu Mar 24 21:22:24 CDT 2011 [ 1301019744151 ]
        Burt Beckwith made changes -
        Workflow jira [ 33136 ] Grails [ 40400 ]
        Burt Beckwith made changes -
        Workflow Grails [ 40400 ] Copy of Grails [ 47831 ]
        Burt Beckwith made changes -
        Workflow Copy of Grails [ 47831 ] Grails [ 55241 ]
        Burt Beckwith made changes -
        Workflow Grails [ 55241 ] Grails2 [ 62790 ]
        Burt Beckwith made changes -
        Workflow Grails2 [ 62790 ] jira [ 76071 ]
        Burt Beckwith made changes -
        Workflow jira [ 76071 ] Grails2 [ 84795 ]
        Peter Ledbrook made changes -
        Last Reviewed 01/Jan/10
        Peter Ledbrook made changes -
        Workflow Grails2 [ 84795 ] jira [ 93225 ]
        Peter Ledbrook made changes -
        Workflow jira [ 93225 ] Grails2 [ 101392 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Daniel Henrique Alves Lima
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Last Reviewed:

              Development