Reputation: 1400
I recently updated my Spring boot project from 1.5.6 to 2.0.2 and having now a problem with one of my entites and their metamodel generation.
The problem occurs with a mapping of Set of Enums which was working before i switched to 2.0.2.
While starting the webapp it shows me the following error in my log:
HHH015007: Illegal argument on static metamodel field injection : xxx.TestEntity_#testEnums; expected type : org.hibernate.metamodel.internal.PluralAttributeImpl$SetAttributeImpl; encountered type : javax.persistence.metamodel.SingularAttribute
The entity and its mapping:
public class TestEntity extends AbstractEntity {
...
@JsonIgnore
@ElementCollection(targetClass = TestEnum.class)
@Convert(converter = TestEnumConverter.class)
@CollectionTable(name = "engine_test_enum", joinColumns = @JoinColumn(name = "test_entity_id"))
private Set<TestEnum> testEnums = new HashSet<>();
...
}
The Enum
public enum TestEnum implements CodeEnum, AliasEnum {
TEST1(1, "ALIAS1"),
TEST2(2, "ALIAS2"),
// ... and so on ...
;
private Integer code;
private String alias;
private TestEnum(Integer code, String alias) {
this.code = code;
this.alias = alias;
}
@Override
public Integer getCode() {
return code;
}
@Override
public String getAlias() {
return alias;
}
}
Converter class
@Converter
public class TestEnumConverter implements AttributeConverter<TestEnum, Integer> {
@Override
public Integer convertToDatabaseColumn(TestEnum testEnum) {
return TestEnum == null ? null : testEnum.getCode();
}
@Override
public TestEnum convertToEntityAttribute(Integer code) {
return EnumUtils.fromCode(TestEnum.class, code);
}
}
Metamodel generated class
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(TestEntity.class)
public abstract class TestEntity_ extends xxx.AbstractEntity_ {
...
public static volatile SingularAttribute<TestEntity, TestEnum> testEnum;
...
}
My dependencies:
Does anybody know the reason for this behavior?
First i thought it was just a problem cleaning the workspace (using eclipse). But regenerating the metamodel classes seem to be ok according to their timestamps.
As we can see the generated class contains indeed a SingularAttribute...but what am i doing wrong that this is not mapped as:
SetAttribute<TestEntity, TestEnum> testEnums;
?
Upvotes: 3
Views: 14604
Reputation: 129
As per the Documentation here :
The Convert annotation should not be used to specify conversion of the following: Id attributes, version attributes, relationship attributes, and attributes explicitly denoted as Enumerated or Temporal.
So instead of an Enum
, you can use an embeddable class and use a dot (".") notation in the attributeName
element to indicate an attribute within an embedded attribute, which in this case will be your embedded class.
Upvotes: 1