Reputation: 31
I have an @ObjectTypeConverter
defined for one of my models like so:
@Column(name = "ACTIVE", nullable = false)
@ObjectTypeConverter(name = "shortToBooleanConverter", dataType = java.lang.Short.class, objectType = java.lang.Boolean.class, defaultObjectValue = "TRUE", conversionValues = {
@ConversionValue(dataValue = "0", objectValue = "False"),
@ConversionValue(dataValue = "1", objectValue = "True")
})
private boolean active;
And similarly in other model like so:
@Column(name = "ACTIVE_COLLECTION", nullable = false)
@ObjectTypeConverter(name = "shortToBooleanConverter", dataType = java.lang.Short.class, objectType = java.lang.Boolean.class, defaultObjectValue = "TRUE", conversionValues = {
@ConversionValue(dataValue = "0", objectValue = "False"),
@ConversionValue(dataValue = "1", objectValue = "True")
})
private boolean activeCollection;
In some cases, I need the same conversion on several variables in the same model.
At runtime, I get an error:
Exception Description: Conflicting annotations with the same name [shortToBooleanConverter] were found. The first one [@org.eclipse.persistence.annotations.ObjectTypeConverter({dataType=java.lang.Short, name=shortToBooleanConverter, conversionValues=[Ljava.lang.Object;@6052474f, objectType=java.lang.Boolean})] was found within [field stillConnected] and the second [@org.eclipse.persistence.annotations.ObjectTypeConverter({defaultObjectValue=TRUE, dataType=java.lang.Short, name=shortToBooleanConverter, conversionValues=[Ljava.lang.Object;@6a3b8f4c, objectType=java.lang.Boolean})] was found within [field active]. Named annotations must be unique across the persistence unit.
What is the best way to address this? One solution I could try is just making the name
attribute unique in each model, but since they're doing the same thing, is there a way to define the converter once and reuse it across multiple models?
Upvotes: 1
Views: 20