Thanks.
First, some code, the problem is described after the code.
Hi. I have the following @Converter class written in Scala:
// This is an abstract class for all optional Enumeration
types
abstract class OptionEnumConverter[T, D](et: Enumeration) extends AttributeConverter[Option[T], String] {
def convertToDatabaseColumn(attribute: Option[T]): String = {
attribute.map(_.toString).orNull
}
def convertToEntityAttribute(dbData: String): Option[T] = {
if (dbData eq null) {
None
} else {
Some(et.withName(dbData).asInstanceOf[T])
}
}
}
@Converter
class InvoiceAttachmentInfoOptionUserType extends OptionEnumConverter[InvoiceAttachmentInfo.ExtendedValue, String](InvoiceAttachmentInfo)
This is the concrete Enum:
object InvoiceAttachmentInfo extends EnumWithDescriptionAndObject[InvoiceTexts.V.ExtendedValue] {
val NONE = Value(InvoiceTexts.V.attachment_none)
val INCLUDE_INVOICE_BASIS = Value(InvoiceTexts.V.attachment_includeInvoiceBasis)
val INCLUDE_INVOICE_BASIS_WITH_PRICE = Value(InvoiceTexts.V.attachment_includeInvoiceBasisWithPrice)
}
This is the abstract Enum:
sealed trait ValueWithDescription[T] {
def description: String
def name: String
def wrapped: T
}
abstract class EnumWithDescriptionAndObject[T] extends Enumeration {
abstract class ExtendedValue(id: Int) extends Val(id) with ValueWithDescription[T]
def Value(inDescription: String, inWrapped: T) = new ExtendedValue(nextId) {
def description = inDescription
def name = toString()
def wrapped = inWrapped
}
def Value(inWrapped: T): ExtendedValue = Value("", inWrapped)
def getValues = {
super.values.map(v => v.asInstanceOf[ExtendedValue]).asInstanceOf[Set[ExtendedValue]].toSeq
}
def valueOf(name: String) = try{Some(withName(name).asInstanceOf[ExtendedValue])} catch {case _: Throwable => None}
def unapply(value: String) = getValues.find(_.toString == value)
}
It all works well using Scala-2.11.7 with normal
compilation and the converter is found, but when using the
following compiler-arguments:
<arg>-Ydelambdafy:method</arg>
<arg>-Ybackend:GenBCode</arg>
<arg>-target:jvm-1.8</arg>
The converter fails to deploy:
Caused
by: Exception [EclipseLink-7352] (Eclipse Persistence
Services - 2.5.2.v20140319-9ad6abd):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: The converter class
[.........InvoiceAttachmentInfoOptionUserType] must
implement the JPA
javax.persistence.AttributeConverter<X, Y>
interface to be a valid converter class.
at
org.eclipse.persistence.exceptions.ValidationException.converterClassMustImplementAttributeConverterInterface(ValidationException.java:2325)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor.initClassificationClasses(ConverterAccessor.java:154)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor.<init>(ConverterAccessor.java:82)
at
org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.initPersistenceUnitClasses(MetadataProcessor.java:364)
at
org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processEntityMappings(MetadataProcessor.java:559)
at
org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:581)
at
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1869)
So there is something with the generated byte-code
which it seems MetadataAsmFactory is not happy with.
Any hints on how to proceed debugging this?
Thanks.
--
Andreas
Joseph Krogh
CTO
/ Partner - Visena AS
Mobile:
+47 909 56 963