1

I'm getting the following error when I try to create an entity graph:

java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [myRelatedObject] on this ManagedType [com.example.RelatedObject]

This is the entity:

@Entity
@Data
@NoArgsConstructor
@NamedEntityGraph(name = "withRelatedObject",
    attributeNodes = {
        @NamedAttributeNode("myRelatedObject")
    })
public class RelatedObject {

  @Id
  @GeneratedValue
  int id;

  @AnyMetaDef(name = "related",
      idType = "integer",
      metaType = "string",
      metaValues = {
          @MetaValue(value = "role", targetEntity = Role.class),
          @MetaValue(value = "user", targetEntity = User.class)
      })
  @Any(metaDef = "related", metaColumn = @Column(name = "type"), fetch = FetchType.LAZY)
  @JoinColumn(name = "related_object")
  private BaseEntity myRelatedObject;

}

Seems that the entity graph has a problem with the @Any annotation but I can't find a single piece of information about how those two interact together.

Does anyone knows what's going on? Is there a way to use entity graphs with @Any?

Thanks

Gonzalo Calvo
  • 304
  • 4
  • 15

0 Answers0