Search in sources :

Example 6 with MappingException

use of io.micronaut.data.exceptions.MappingException in project micronaut-data by micronaut-projects.

the class SqlQueryBuilder method resolveJoinTableAssociatedColumns.

@NonNull
private List<String> resolveJoinTableAssociatedColumns(AnnotationMetadata annotationMetadata, boolean associationOwner, PersistentEntity entity, NamingStrategy namingStrategy) {
    List<String> joinColumns = getJoinedColumns(annotationMetadata, associationOwner, "referencedColumnName");
    if (!joinColumns.isEmpty()) {
        return joinColumns;
    }
    PersistentProperty identity = entity.getIdentity();
    if (identity == null) {
        throw new MappingException("Cannot have a foreign key association without an ID on entity: " + entity.getName());
    }
    List<String> columns = new ArrayList<>();
    traversePersistentProperties(identity, (associations, property) -> {
        String columnName = namingStrategy.mappedName(associations, property);
        columns.add(columnName);
    });
    return columns;
}
Also used : ArrayList(java.util.ArrayList) PersistentProperty(io.micronaut.data.model.PersistentProperty) MappingException(io.micronaut.data.exceptions.MappingException) NonNull(io.micronaut.core.annotation.NonNull)

Aggregations

MappingException (io.micronaut.data.exceptions.MappingException)6 PersistentProperty (io.micronaut.data.model.PersistentProperty)6 NonNull (io.micronaut.core.annotation.NonNull)5 ArrayList (java.util.ArrayList)5 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)4 Relation (io.micronaut.data.annotation.Relation)4 Association (io.micronaut.data.model.Association)4 PersistentPropertyPath (io.micronaut.data.model.PersistentPropertyPath)4 NamingStrategy (io.micronaut.data.model.naming.NamingStrategy)4 ArgumentUtils (io.micronaut.core.util.ArgumentUtils)3 CollectionUtils (io.micronaut.core.util.CollectionUtils)3 StringUtils (io.micronaut.core.util.StringUtils)3 Embedded (io.micronaut.data.model.Embedded)3 Pageable (io.micronaut.data.model.Pageable)3 PersistentEntity (io.micronaut.data.model.PersistentEntity)3 JoinPath (io.micronaut.data.model.query.JoinPath)3 QueryModel (io.micronaut.data.model.query.QueryModel)3 QueryBuilder (io.micronaut.data.model.query.builder.QueryBuilder)3 QueryParameterBinding (io.micronaut.data.model.query.builder.QueryParameterBinding)3 QueryResult (io.micronaut.data.model.query.builder.QueryResult)3