amacleay-cohere opened a new issue, #14382:
URL: https://github.com/apache/grails-core/issues/14382
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
```groovy
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:
```groovy
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)
}
```
```groovy
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)
```
--
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]