# How to use Kotlin Null-Safe feature with Hibernate + Oracle empty Strings

**URL:** <https://discuss.kotlinlang.org/t/how-to-use-kotlin-null-safe-feature-with-hibernate-oracle-empty-strings/5625>\
**Category:** Support\
**Created:** [November 30, 2017, 2:45pm UTC](https://discuss.kotlinlang.org/t/how-to-use-kotlin-null-safe-feature-with-hibernate-oracle-empty-strings/5625 "2017-11-30T14:45:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mshvach](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@mshvach](https://discuss.kotlinlang.org/u/mshvach)\
**Post date:** [November 30, 2017, 2:45pm UTC](https://discuss.kotlinlang.org/t/how-to-use-kotlin-null-safe-feature-with-hibernate-oracle-empty-strings/5625/1 "2017-11-30T14:45:07Z")

</div>

Hi Guys,

I want to use null-save value in JPA Entity. I can create this entity at database with Hibernate. Oracle can’t  
distinguish empty string and null. It stores null anyway in table. When I try load this instance from database I have null value at firstName and secondName fields despite they are null-save

```
@Entity
class MyEntity {
    @Id 
    val int id;
    @Column
    var firstName: String = ""
    @Column
    var secondName: String = ""
}

```

Please advise how to resolve it

---

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [November 30, 2017, 9:28pm UTC](https://discuss.kotlinlang.org/t/how-to-use-kotlin-null-safe-feature-with-hibernate-oracle-empty-strings/5625/2 "2017-11-30T21:28:32Z")

</div>

Had you look at `Converter`?

See an example here:

[https://javaee.github.io/javaee-spec/javadocs/javax/persistence/Convert.html](https://javaee.github.io/javaee-spec/javadocs/javax/persistence/Convert.html)

---

<div class="post-metadata">

**Author:** ![mshvach](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@mshvach](https://discuss.kotlinlang.org/u/mshvach)\
**Post date:** [December 5, 2017, 1:58pm UTC](https://discuss.kotlinlang.org/t/how-to-use-kotlin-null-safe-feature-with-hibernate-oracle-empty-strings/5625/3 "2017-12-05T13:58:04Z")

</div>

@fvasco thank you it helped and works great! 🙂

```
@Converter(autoApply = true)
class StringConverter : Attribute<String, String> {
  override fun convertToEntityAttribute(dbData: String?): String = dbData ?: ""
  override fun convertToDatabaseColumn(attribue: String?): String? = attribute
}

```

---

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [December 5, 2017, 2:13pm UTC](https://discuss.kotlinlang.org/t/how-to-use-kotlin-null-safe-feature-with-hibernate-oracle-empty-strings/5625/4 "2017-12-05T14:13:54Z")

</div>

You’re welcome
