0

With Spring data mongodb I have a couple of entities Person and Dog. Linked with DBRef, but pet property in Person can have multiple implementations and can be linked to different collections.

@Document
public class Person {
  @Id
  private String id;
  private String name;
  @DBRef(lazy = true)
  private Pet pet;
}
public interface Pet {
  public String getId();
  public void setId(String id);
  public String getName();
  public void setName(String name);
}
@Document
public class Dog implements Pet {
  @Id
  private String id;
  private String name;
}

Now when I try to check, it always returns me false. basically underlying lazyloading proxy is not implementing the target class. anyway to ensure that lazy loading proxy implements target class.

person.getPet() instanceof Dog
kriegaex
  • 63,017
  • 15
  • 111
  • 202
Jigar Parekh
  • 6,163
  • 7
  • 44
  • 64
  • 1
    Is there an actual question? Please learn [how to ask a question on SO](https://stackoverflow.com/help/how-to-ask) and provide a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve). Thank you. – kriegaex Apr 09 '23 at 08:44

0 Answers0