# Hibernate 5.2.18 cannot get a lazy OneToOne anymore

**URL:** <https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881>\
**Category:** Hibernate ORM\
**Created:** [December 21, 2020, 9:48pm UTC](https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881 "2020-12-21T21:48:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesd](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jamesd](https://discourse.hibernate.org/u/jamesd)\
**Post date:** [December 21, 2020, 9:48pm UTC](https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881/1 "2020-12-21T21:48:42Z")

</div>

I’ve been reading a number of things around the web on this, so it’s not a completely uninformed question here. According to @vlad in a number of places, in order to get a lazy OneToOne to work, we can either

1. Activate Lazy Loading Bytecode Enhancement or
2. Get rid of the parent `@OneToOne` and use `@MapsId` on the child.

Unfortunately, for our application we’re coming from Hibernate 4, and due to amount of disturbance it would cause for us, we can’t really do #2. This leaves #1, but we do not use Gradle nor do we use Maven, we use Bazel. This was not an issue in Hibernate 4 for us, due to the trick with optional=false…but now we’re kind of stuck.

Is there any way to enable bytecode enhancement at run time? I tried these settings I see in the docs for 5.3 but to no avail:

> **[Hibernate ORM 5.3.20.Final User Guide](https://docs.jboss.org/hibernate/orm/5.3/userguide/html_single/Hibernate_User_Guide.html#BytecodeEnhancement-enhancement-runtime)**

Thanks for any help you can lend!

-Jamie

---

<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:** [December 22, 2020, 9:25am UTC](https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881/2 "2020-12-22T09:25:30Z")

</div>

I think this was fixed in 5.4, so maybe you could try to update to the latest version?

---

<div class="post-metadata">

**Author:** ![jamesd](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jamesd](https://discourse.hibernate.org/u/jamesd)\
**Post date:** [December 22, 2020, 12:27pm UTC](https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881/3 "2020-12-22T12:27:22Z")

</div>

@beikov when you say “fixed” what exactly does that mean? What part? We also don’t use entity manager, and the flags in 5.2 appear to only matter if you’re using that.

---

<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:** [December 22, 2020, 1:37pm UTC](https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881/4 "2020-12-22T13:37:47Z")

</div>

By fixed I mean that 5.4 does not require eager joining for all one-to-one associations anymore.

---

<div class="post-metadata">

**Author:** ![jamesd](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jamesd](https://discourse.hibernate.org/u/jamesd)\
**Post date:** [December 22, 2020, 1:53pm UTC](https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881/5 "2020-12-22T13:53:43Z")

</div>

Thanks @beikov. Do you have any specific documentation I could look at for the correct way to setup the parent and child side of onetoone in 5.4?

---

<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:** [December 22, 2020, 2:38pm UTC](https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881/6 "2020-12-22T14:38:06Z")

</div>

There is only an owning side (where the FK column is) and an inverse side, not sure what you mean by parent/child. There is not much you can do wrong here, just map it as lazy and use mappedBy on the inverse side:

```auto
@Entity
class Entity1 {
  @OneToOne(fetch = LAZY)
  @JoinColumn(name = "...")
  Entity1 e1;
}

@Entity
class Entity2 {
  @OneToOne(fetch = LAZY, mappedBy = "entity2")
  Entity1 e1;
}

```

---

<div class="post-metadata">

**Author:** ![jamesd](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jamesd](https://discourse.hibernate.org/u/jamesd)\
**Post date:** [December 22, 2020, 3:16pm UTC](https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881/7 "2020-12-22T15:16:48Z")

</div>

Thanks @beikov let me give this a whirl. What I meant about parent/child is that in your example the “owning side” (where the FK column is) would be the child.

Hopefully this works! Thanks.

-Jamie

---

<div class="post-metadata">

**Author:** ![jamesd](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@jamesd](https://discourse.hibernate.org/u/jamesd)\
**Post date:** [December 30, 2020, 8:21pm UTC](https://discourse.hibernate.org/t/hibernate-5-2-18-cannot-get-a-lazy-onetoone-anymore/4881/8 "2020-12-30T20:21:01Z")

</div>

You’re the man @beikov. Indeed if you use LAZY fetch type and optional false, onetoone is lazy!
