I have this model which works with Gorm3
class UserDataPoint implements Serializable {
User user
DataPoint dataPoint
static mapping = {
id composite: ['user', 'dataPoint']
}
static List<Long> getReadDataPointIds(User user, List<Long> locationIds = null) {
createCriteria().list {
eq('user', user)
dataPoint {
listing {
location {
inList('id', locationIds)
}
}
}
projections {
property('dataPoint.id')
}
} as List
}
}
but now it runs this exception :
java.lang.IllegalArgumentException: Unable to locate Attribute with the the given
name [dataPoint] on this ManagedType [user.UserDataPoint]
Some debug allows me to understand what is happening, it seems that GORM remove the user and dataPoint properties from HibernateProperties because the are a part of the Composite ID
public abstract class AbstractPersistentEntity<T extends Entity> implements PersistentEntity {
.......
IdentityMapping identifier = mapping != null ? mapping.getIdentifier() : null;
if(identity == null && identifier != null) {
final String[] identifierName = identifier.getIdentifierName();
final MappingContext mappingContext = getMappingContext();
if(identifierName.length > 1) {
compositeIdentity = mappingContext.getMappingSyntaxStrategy().getCompositeIdentity(javaClass, mappingContext);
}
for (String in : identifierName) {
final PersistentProperty p = propertiesByName.get(in);
if(p != null) {
persistentProperties.remove(p);
}
persistentPropertyNames.remove(in);
}
disableDefaultId();
}
......
}
So I understand the problem, but I don't know how to fix it ?
how to reference the composite ID and it fields in the projection ?
It seems to be fixed with this recent version https://github.com/grails/gorm-hibernate5/releases/tag/v7.2.1