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

Nested objects have to be set as "embedded" even when they are all in src/main/groovy. #540

Open
douglasom opened this issue Jul 3, 2022 · 0 comments

Comments

@douglasom
Copy link

Nested objects have to be set as "embedded" to be persisted even when they are all in src/main/groovy. I believe non entity classes should always be saved as embedded objects. Above all, non entity objects should never have to have static embedded declarations.

The following test only pass when the commented lines get uncommented. I believe it would be more appropriate if it passed even without those commented lines.


import grails.gorm.tests.GormDatastoreSpec
import grails.persistence.Entity

class EmbeddedWithinEmbeddedSimpleObjectSpec extends GormDatastoreSpec {

    void "Test embedded nested non-domain object"() {
        when:"An entity with a simple nested non-domain embedded object is persisted"
            def constellation = new Constellation(displayName: "foo", solarSystem: new SolarSystem(planet: new Planet(name: "earth")))
            constellation.save(flush:true)
            session.clear()
            constellation = Constellation.get(constellation.id)
        then:"The embedded association is persisted correctly"
            constellation.solarSystem?.planet?.name == 'earth'
    }

    @Override
    List getDomainClasses() {
        [Constellation]
    }
}

@Entity
class Constellation {

    String id
    String displayName

    SolarSystem solarSystem

    static embedded = [ 'solarSystem' ]
}

//@Entity
class SolarSystem {
    Planet planet

//    static embedded = [ 'planet' ]
}

//@Entity
class Planet {
    String name
}
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