Oribow opened a new issue, #14374:
URL: https://github.com/apache/grails-core/issues/14374
I have a domain object with a collection of non-domain objects.
```
class Person{
static hasMany = [knownContacts: KnownContacts]
}
enum KnownContacts{
None,
Email,
Phone
}
```
I want to use this "association" in a criteria, but that throws a
`groovy.lang.MissingMethodException: No signature of method` error at
`knownContacts { ... }`.
```
{
projections {
knownContacts {
id()
}
}
}
```
This is because gorm treats the "knownContacts" not as an association, but
as an ELEMENT_COLLECTION.
Which means the isAssociation check fails on it, as its
PersistentAttributeType is ELEMENT_COLLECTION.
```
public boolean isAssociation() {
return getPersistentAttributeType() ==
PersistentAttributeType.ONE_TO_MANY
|| getPersistentAttributeType() ==
PersistentAttributeType.MANY_TO_MANY;
}
```
There doesn't seem to be any code in
AbstractHibernateCriteriaBuilder.invokeMethod that deals with
ELEMENT_COLLECTIONs.
```
if (pd != null && pd.getReadMethod() != null) {
final Metamodel metamodel = sessionFactory.getMetamodel();
final EntityType<?> entityType =
metamodel.entity(targetClass);
final Attribute<?, ?> attribute =
entityType.getAttribute(name);
if (attribute.isAssociation())
[...]
```
The `attribute.isAssociation` check fails and the `throw new
MissingMethodException(name, getClass(), args);` at the end of the method is
reached.
I'm not sure if this is intentional or an oversight. Is there a different
way we are supposed to query non domain to domain associations?
The generated database schema creates an extra table for ELEMENT_COLLECTION
(at least in this case) so I'm not sure why they can't be used like regular
associations between domain objects.
--
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]