Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Error in converters when having hierarchy of classes with different generic-types

Hi Andreas,

Can you please enter a bug with your example that reproduces the issue?

Thanks,
Guy

On 16/08/2013 6:54 AM, Andreas Joseph Krogh wrote:
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.
 
--
Andreas Joseph Krogh <andreak@xxxxxxxxxxxx>      mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--

Oracle
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4

Green
            Oracle Oracle is committed to developing practices and products that help protect the environment


Back to the top