AmaliaMV opened a new issue, #14564:
URL: https://github.com/apache/grails-core/issues/14564

   I want to save an object, but first I need to get its `ID` to update another 
property of the same object. I am doing this:
   
   ```
           if (instance.validate()) {
               instance.save()  // now I have an id
               instance.code = String.format("%014d", instance.id)
               instance.save()
           }
   ```
   
   The domain object is
   ```
   class Product {
   
       final static String DEFAULT_CODE = "XXXX-XXXX-XXXX"
   
       String code = DEFAULT_CODE
       String description
   
       static constraints = {
           code size: 14..14
       }
   }
   ```
   
   But when I get the object from the data base, the `code` property doesn't 
have the new value. I created an integration test to show this:
   
   ```
   void "test double saved"() {
           given:
           RestBuilder rest = new RestBuilder()
   
           when: "save a new product"
           RestResponse response = 
rest.post("http://localhost:${serverPort}/product";) {
               json([
                   description: "screw"
               ])
           }
   
           then: "the code will be different to default value"
           response.status == 201
           Product product = Product.getAll().first()
           product
           product.code != Product.DEFAULT_CODE
   
           cleanup:
           Product.withNewSession {
               Product.withNewTransaction {
                   Product.getAll()*.delete()
               }
           }
       }
   ```
   The second call to save() is ignored. 
   
   Here is the sample app: https://github.com/AmaliaMV/neo4j-doubleSaved
   
   The versions I am using are:
   
   ```
   grailsVersion=3.3.5
   gormVersion=6.1.10.BUILD-SNAPSHOT
   grailsNeo4jPluginVersion=6.2.0.BUILD-SNAPSHOT
   ```
   
   However, I checked that this is happening too if I use hibernate instead of 
neo4j.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to