I wonder: is anyone using Arrow in a project with ...
# arrow
m
I wonder: is anyone using Arrow in a project with JPA? I'd prefer to model
null
values in the DB using Arrow's
Option<T>
instead of
T?
. But I guess that Hibernate probably wouldn't know how to deal with
Option
?
r
Hi @Marcus Ilgner, I'm not aware of anyone using arrow and hibernate combined, normally it's exposed or other Kotlin ORM like libraries combined with Arrow. I suppose to use
Option
in Hibernate you would have to implement a
AttributeConverter
or similar interface to tell Hibernate how to serialize and deserialize the value: Something like this, untested and assuming Hibernate would support polymorphic converters with generic type args:
Copy code
import javax.persistence.AttributeConverter
import javax.persistence.Converter

@Converter
class OptionConverter<A> : AttributeConverter<Option<A>, A> {
  fun convertToDatabaseColumn(optionValue: Option<A>): A? =
    optionValue.getOrElse { null }

  fun convertToEntityAttribute(dbValue: A?): Option<A> =
    Option.fromNullable(dbValue)
}
m
I'll give it a try! Thank you! I'm sure I'll get it to work somehow, but wanted to check whether someone already had a solution. In case the attribute converter method doesn't work, I'll publish whatever alternative I come up with.
thank you color 1
o
Probably too far from the initial question, but Spring Data JPA does support the following wrapper types •
java.util.Optional
com.google.common.base.Optional
scala.Option
io.vavr.control.Option
My gut tells me, that things could work with Kotlin-Vavr, too. Integration code doesn't seem much, you could do a PR for Arrow's Option<T>. 🤪
🙌 1