Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double saved #91

Open
AmaliaMV opened this issue Jun 6, 2018 · 0 comments
Open

Double saved #91

AmaliaMV opened this issue Jun 6, 2018 · 0 comments

Comments

@AmaliaMV
Copy link

AmaliaMV commented Jun 6, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant