I use OpenJPA in my Java project. The question is about a non-nullable integer column.
Currently this field is mapped to an enum class by the ordinal index:
@Column(nullable=false)
@Enumerated(EnumType.ORDINAL)
Instead, I'd like to map this db-side integer column to a custom object.
Something like
@Column(nullable=false)
@CustomObject( dbtype=java.sql.Types.INTEGER, // What do we find in the DB table?
intValue -> MyObjectsRepository.getInstance( intValue ), // Integer to MyObject
myObject -> myObject.getIntValue() ) // MyObject to Integer
Does this exist?
In the best case, there is a JPA-way (implementation agnostic). But if there's only an OpenJPA-only trick, that would help me as well.