Skip to content

Errorhandling when referencing non-entities in collections. #18

@ilikeorangutans

Description

@ilikeorangutans

Right now when non-entity, i.e. a class that lacks the @entity annotation, is referenced in a collection, the MappingExtractor will crash with a confusing exception:

org.om.core.api.exception.MappingException: Target type interface java.util.List is not an entity. (in com.foo.type.that.ReferencesTheNonEntity)
    at org.om.core.impl.mapping.extractor.FieldMappingExtractorImpl.extract(FieldMappingExtractorImpl.java:88)
    at org.om.core.impl.mapping.extractor.EntityMappingExtractorImpl.extractFields(EntityMappingExtractorImpl.java:66)
    at org.om.core.impl.mapping.extractor.EntityMappingExtractorImpl.extract(EntityMappingExtractorImpl.java:43)
    at org.om.core.impl.mapping.registry.OnDemandMappingRegistry.getMapping(OnDemandMappingRegistry.java:25)
    at org.om.core.impl.session.ImmutableSessionImpl.get(ImmutableSessionImpl.java:56)

To reproduce:

Type A has a collection mapping

@Entity
class A {
  @Collection(targetType=B.class)
  private List<B> bs;
}

However, B is not an entity:

class B {   }

The error message should be more clear on what happens and provide guidance how to resolve the situation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions