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

Unable to query embedded objects with @Where annotation on data service #195

Open
amacleay-cohere opened this issue Jan 29, 2021 · 0 comments
Assignees

Comments

@amacleay-cohere
Copy link
Contributor

This issue is WIP - I apologize for the lack of detail at this point. I will be adding to it presently.

I have a simple POGO class that has an embedded property

package com.partypeople

import grails.persistence.Entity
import javax.persistence.Embeddable

@Entity
class PersonAttribute {
  String id
  List<AttributeContext> contexts = []
  static embedded = ['contexts']
}
@Embeddable
class AttributeContext {

    String id
    String neighborhoodId

    static belongsTo = [attribute: PersonAttribute]

}

I would like to generate a query on an embedded field:

package com.partypeople

import grails.gorm.services.Service
import grails.gorm.services.Where

@Service(PersonAttribute)
interface PersonAttributeDataService {

    @Where({ contexts { neighborhoodId == neighborhoodId } })
    List<PersonAttribute> findByNeighborhoodId(String neighborhoodId)
}
package com.partypeople

import grails.test.mongodb.MongoSpec
import grails.testing.gorm.DataTest
import grails.testing.services.ServiceUnitTest

class PatientAttributeDataServiceSpec extends MongoSpec implements DataTest, ServiceUnitTest<PersonAttributeDataService> {

    void "Can do"() {
        given:
        def attribute = new PersonAttribute(contexts: [new AttributeContext(neighborhoodId: '1234')])
        attribute.save()

        when:
        def res = service.findByNeighborhoodId('1234')

        then:
        res.size() == 1
        res[0].contexts.neighborhoodId == '1234'
    }
}

Fails with

java.lang.NullPointerException
	at org.grails.datastore.mapping.model.AbstractPersistentEntity.isIdentityName(AbstractPersistentEntity.java:292)
	at org.grails.datastore.bson.query.BsonQuery.getPropertyName(BsonQuery.java:698)
	at org.grails.datastore.bson.query.BsonQuery.getPropertyName(BsonQuery.java:694)
amacleay-cohere added a commit to amacleay-cohere/gorm-mongodb that referenced this issue Jan 30, 2021
See grails#195

Note: test is not currently functional: failing to instantiate data
service for test.
@puneetbehl puneetbehl self-assigned this Nov 7, 2024
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

2 participants