/** * @return The inverse side or null if the association is not bidirectional */ public Association getInverseSide() { final PersistentProperty associatedProperty = associatedEntity.getPropertyByName(referencedPropertyName); if (associatedProperty == null) return null; if (associatedProperty instanceof Association) { return (Association) associatedProperty; } throw new IllegalMappingException("The inverse side [" + associatedEntity.getName() + "." + associatedProperty.getName() + "] of the association [" + getOwner().getName() + "." + getName() + "] is not valid. Associations can only map to other entities and collection types."); }
/** * @see org.grails.datastore.mapping.model.MappingConfigurationStrategy#getIdentity(Class, org.grails.datastore.mapping.model.MappingContext) */ public PersistentProperty getIdentity(Class javaClass, MappingContext context) { ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(javaClass); PersistentEntity entity = context.getPersistentEntity(javaClass.getName()); ClassMapping mapping = entity.getMapping(); IdentityMapping id = mapping.getIdentifier(); final String[] names = id.getIdentifierName(); if (names.length == 1) { final PropertyDescriptor pd = cpf.getPropertyDescriptor(names[0]); if (pd != null) { return propertyFactory.createIdentity(entity, context, pd); } if (!entity.isExternal() && isAbstract(entity)) { throw new IllegalMappingException("Mapped identifier [" + names[0] + "] for class [" + javaClass.getName() + "] is not a valid property"); } return null; } return null; }
@Override public PersistentProperty[] getCompositeIdentity(Class javaClass, MappingContext context) { ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(javaClass); PersistentEntity entity = context.getPersistentEntity(javaClass.getName()); ClassMapping mapping = entity.getMapping(); IdentityMapping id = mapping.getIdentifier(); final String[] names = id.getIdentifierName(); PersistentProperty[] identifiers = new PersistentProperty[names.length]; for (int i = 0; i < names.length; i++) { String name = names[i]; final PersistentProperty p = entity.getPropertyByName(name); if(p != null) { identifiers[i] = p; } else { final PropertyDescriptor pd = cpf.getPropertyDescriptor(name); if (pd != null) { identifiers[i] = propertyFactory.createIdentity(entity, context, pd); } else { throw new IllegalMappingException("Invalid composite id mapping. Could not resolve property ["+name+"] for entity ["+javaClass.getName()+"]"); } } } return identifiers; }
return null; throw new IllegalMappingException("Non-existent mapping property [" + mappingProperty + "] specified for property [" + property.getName() + "] in class [" + entity.getJavaClass().getName() + "]");