# @LazyToOne deprecated

**URL:** <https://discourse.hibernate.org/t/lazytoone-deprecated/8282>\
**Category:** Hibernate ORM\
**Created:** [September 21, 2023, 11:57am UTC](https://discourse.hibernate.org/t/lazytoone-deprecated/8282 "2023-09-21T11:57:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohd\_Salim](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mohd_salim/32/2671_2.png) [@Mohd\_Salim](https://discourse.hibernate.org/u/Mohd_Salim)\
**Post date:** [September 21, 2023, 11:57am UTC](https://discourse.hibernate.org/t/lazytoone-deprecated/8282/1 "2023-09-21T11:57:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mohd\_Salim](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mohd_salim/32/2671_2.png) [@Mohd\_Salim](https://discourse.hibernate.org/u/Mohd_Salim)\
**Post date:** [September 21, 2023, 12:00pm UTC](https://discourse.hibernate.org/t/lazytoone-deprecated/8282/2 "2023-09-21T12:00:07Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [September 21, 2023, 12:52pm UTC](https://discourse.hibernate.org/t/lazytoone-deprecated/8282/3 "2023-09-21T12:52:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mohd\_Salim](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mohd_salim/32/2671_2.png) [@Mohd\_Salim](https://discourse.hibernate.org/u/Mohd_Salim)\
**Post date:** [September 22, 2023, 1:45pm UTC](https://discourse.hibernate.org/t/lazytoone-deprecated/8282/4 "2023-09-22T13:45:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mohd\_Salim](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mohd_salim/32/2671_2.png) [@Mohd\_Salim](https://discourse.hibernate.org/u/Mohd_Salim)\
**Post date:** [September 22, 2023, 1:53pm UTC](https://discourse.hibernate.org/t/lazytoone-deprecated/8282/5 "2023-09-22T13:53:20Z")

</div>

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

```auto
  @Test
  void mainCanBeFetchedByCrn() {

    Main savedmain =
        mainRepository.save(
            mainRepositoryDataProvider.createValidmain());

    entityManager.flush();
    entityManager.clear();

    List<Main> list =
        mainRepository.findByReferenceNumberCrn(crn, mainStatus.DRAFT);
    Optional<Main> main =
        list.stream()
            .filter(
                x ->
                    x.getReferenceNumber() != null
                        && x.getReferenceNumber()
                            .getCrn()
                            .getCrnNumber()
                            .equals(savedmain.getReferenceNumber().getCrn().getCrnNumber()))
            .findAny();

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

```

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [September 22, 2023, 2:42pm UTC](https://discourse.hibernate.org/t/lazytoone-deprecated/8282/6 "2023-09-22T14:42:03Z")

</div>

If you think this is a bug, please create an issue in the issue tracker([https://hibernate.atlassian.net](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](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.

---

<div class="post-metadata">

**Author:** ![Mohd\_Salim](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mohd_salim/32/2671_2.png) [@Mohd\_Salim](https://discourse.hibernate.org/u/Mohd_Salim)\
**Post date:** [September 26, 2023, 5:46am UTC](https://discourse.hibernate.org/t/lazytoone-deprecated/8282/7 "2023-09-26T05:46:47Z")

</div>

Hello @beikov ,

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

[https://hibernate.atlassian.net/browse/HHH-17258](https://hibernate.atlassian.net/browse/HHH-17258)

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

Thanks.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [September 26, 2023, 12:38pm UTC](https://discourse.hibernate.org/t/lazytoone-deprecated/8282/8 "2023-09-26T12:38:11Z")

</div>

As @mbladel answered on JIRA, this will be fixed with the next release, since it is a duplicate of [[HHH-17228] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-17228)
