@LazyToOne deprecated

@LazyToOne is deprecated, than what is the alternative to it ?

I had this code… but now it shows deprecated … what to do ?

@OneToOne(cascade = CascadeType.ALL, mappedBy = "animal", fetch = FetchType.LAZY)
  @LazyToOne(value = LazyToOneOption.NO_PROXY)
  private Giraffe giraffe;

What do you want to express/achieve with this annotation? Chances are, you don’t need this anymore and you can simply remove the annotation.

Okay … When I simply remove this annotation … and retrieve an object of the class in which this girrafe onetoone relation was present (let’s say Main class) … this giraffe object was null in the retrieved entity i think.

Or may be it was loaded somehow but its child objects were null. or not loaded.

Example… I had this test… and It was failing on this line …
assertEquals(1, main.get().getMasterAnimal().getAdditionalInformation().size());

  void mainCanBeFetchedByCrn() {

    Main savedmain =


    List<Main> list =
        mainRepository.findByReferenceNumberCrn(crn, mainStatus.DRAFT);
    Optional<Main> main =
                x ->
                    x.getReferenceNumber() != null
                        && x.getReferenceNumber()

    log.info("fetching master Animal : ");
    log.info("fetching master Animals additional info : ");
    **assertEquals(1, main.get().getMasterAnimal().getAdditionalInformation().size());**

If you think this is a bug, please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the issue.

Hello @beikov ,

Thank you for your response, I think the above issue might be related to this one.


Could you please suggest a workaround if the fix is not possible in near future.


As @mbladel answered on JIRA, this will be fixed with the next release, since it is a duplicate of [HHH-17228] - Hibernate JIRA