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


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

class MyEntity {
    val int id;
    var firstName: String = ""
    var secondName: String = ""

Please advise how to resolve it


Had you look at Converter?

See an example here:


@fvasco thank you it helped and works great! :slightly_smiling_face:

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


You’re welcome