# NotNull annotation is not operating as expected - 5.4.18.Final

**URL:** https://discourse.hibernate.org/t/notnull-annotation-is-not-operating-as-expected-5-4-18-final/5417
**Category:** Hibernate ORM
**Created:** [June 7, 2021, 9:14am UTC](https://discourse.hibernate.org/t/notnull-annotation-is-not-operating-as-expected-5-4-18-final/5417 "2021-06-07T09:14:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![IoannaDim](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@IoannaDim](https://discourse.hibernate.org/u/IoannaDim)
#### Post date: [June 7, 2021, 9:14am UTC](https://discourse.hibernate.org/t/notnull-annotation-is-not-operating-as-expected-5-4-18-final/5417/1 "2021-06-07T09:14:17Z")

</div>

I have upgraded my hibernate- core library from 5.4.11.Final to 5.4.18.Final release. During unit testing, I have noticed that in cases where NotNull annotation is used for ManyToOne JPA joins, the expected inner join in the generated query became left outer join. It seems that for 5.4.18.Final release NotNull annotation in for these cases is not operating as expected. Is there any explanation for this?

Note: I have by passed it by removing @NotNull before the @ManyToOne and by applying optional = false.

---

<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: [June 7, 2021, 11:37am UTC](https://discourse.hibernate.org/t/notnull-annotation-is-not-operating-as-expected-5-4-18-final/5417/2 "2021-06-07T11:37:19Z")

</div>

This was a bug that was fixed some version. If you want the JPA association to be non-optional you must specify `optional = false` like you seem to have figured out already.

---

<div class="post-metadata">

### Author: ![IoannaDim](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@IoannaDim](https://discourse.hibernate.org/u/IoannaDim)
#### Post date: [June 7, 2021, 1:38pm UTC](https://discourse.hibernate.org/t/notnull-annotation-is-not-operating-as-expected-5-4-18-final/5417/3 "2021-06-07T13:38:50Z")

</div>

Thank you very much for your response! Could you please specify which was that bug exactly? I need to include this information to the relevant documentation of hibernate upgrade for my code.

---

<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: [June 7, 2021, 2:37pm UTC](https://discourse.hibernate.org/t/notnull-annotation-is-not-operating-as-expected-5-4-18-final/5417/4 "2021-06-07T14:37:25Z")

</div>

I think it was [[HHH-14129] Bidirectional relationship with @NotNull fails to save - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-14129) but I really can’t remember anymore. You would have to look into the issue tracker.

---

<div class="post-metadata">

### Author: ![IoannaDim](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@IoannaDim](https://discourse.hibernate.org/u/IoannaDim)
#### Post date: [June 7, 2021, 2:38pm UTC](https://discourse.hibernate.org/t/notnull-annotation-is-not-operating-as-expected-5-4-18-final/5417/5 "2021-06-07T14:38:31Z")

</div>

I am really grateful! Thank you! 🙂
