Hi.
I'm trying to make a generic Option-converter (for Scala's
Option):
abstract class OptionConverter[T, JDBCType] extends AttributeConverter[Option[T], JDBCType] {
def convertToDatabaseColumn(attribute: Option[T]): JDBCType = {
attribute match {
case Some(e) => toJdbcType(e)
case _ => null.asInstanceOf[JDBCType]
}
}
def convertToEntityAttribute(dbData: JDBCType): Option[T] = {
if (dbData == null) {
None
} else {
Some(fromJdbcType(dbData))
}
}
def fromJdbcType(value: JDBCType): T
def toJdbcType(value: T): JDBCType
}
@Converter(autoApply = true)
class OptionLongConverter extends OptionConverter[Long, lang.Long]{
def fromJdbcType(value: lang.Long): Long = value.toLong
def toJdbcType(value: Long): lang.Long = lang.Long.valueOf(value)
}
This compiles fine but gives me a runtime-error when
retrieving an entity with Option[Long] as attribute:
Caused by: Exception [EclipseLink-3002] (Eclipse
Persistence Services - 2.5.1.v20130814-ad1d746):
org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [23], of class [class
java.lang.Long], from mapping
[org.eclipse.persistence.mappings.DirectToFieldMapping[budget-->project.budget]]
with descriptor
[RelationalDescriptor(no.officenet.example.rpm.projectmgmt.domain.model.entities.Project
--> [DatabaseTable(project)])], could not be converted to
[class [B].
It seems the logic for infering the type-parameters of the
converter doesn't handle this well.
Any chance this may be fixed?
If interessted I can provide an example-project illustrating
this.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
--

Guy Pelletier
ORACLE Canada,
45 O'Connor Street
Suite 400
Ottawa, Ontario
Canada K1P 1A4
Oracle is committed to developing practices
and products that help protect the environment